Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve sub frame decode performance #777

Merged
merged 30 commits into from
Nov 8, 2024

Conversation

jean-roland
Copy link
Contributor

@jean-roland jean-roland commented Nov 6, 2024

The introduction of batching revealed lot of room to improve performance in frame decoding. The will be split in a subscriber focused PR (this one) and a query focused one (TBD).

  • Introduce Memoization (off by default):

One of the costliest operation in subscriber triggering was the construction of the key-expression and the callback lookup. Memoizing the results improved significantly performance. Although the current implementation is a bit trivial as it only holds one entry. Probably worth adding a true lru cache implementation in next PR (open to suggestion).

  • Frame decoding buffer switch from vec to svec;

With frames containing 4000+ frames, the use of reference vectors were causing a lot of memory fragmentation and inefficiencies. The use of svec is much better but require to minimize reallocation, thus a configurable Z_CONFIG_FRAME_AVG_MSG_SIZE has been introduced to strike a balance between memory consumption and time spent on reallocation.

Svec/elem were a bit improved as well (added the elem_move, ability to choose default svec move/copy behaviour with boolean, return result instead of bool...)

  • Removed redundant initialization and drop:

There were a few cases of superfluous or redundant type init and clear. Specifically on the network messages and they were removed.

Copy link

github-actions bot commented Nov 6, 2024

PR missing one of the required labels: {'breaking-change', 'new feature', 'bug', 'dependencies', 'enhancement', 'documentation', 'internal'}

@jean-roland jean-roland added the enhancement Things could work better label Nov 6, 2024
@jean-roland jean-roland requested a review from sashacmc November 6, 2024 09:27
@@ -45,6 +45,7 @@
#define Z_FEATURE_LOCAL_SUBSCRIBER 0
#define Z_FEATURE_PUBLISHER_SESSION_CHECK 1
#define Z_FEATURE_BATCHING 1
#define Z_FEATURE_MEMOIZATION 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#define Z_FEATURE_MEMOIZATION 0
#define Z_FEATURE_MEMORIZATION 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The technical term is Memoization though, https://en.wikipedia.org/wiki/Memoization. But yeah that might not be transparent to the user, in that case we might as well go to something like Z_FEATURE_RX_CACHE

src/protocol/codec/message.c Show resolved Hide resolved
@@ -28,6 +28,10 @@
#include "zenoh-pico/utils/logging.h"
#include "zenoh-pico/utils/result.h"

#define _Z_FRAME_VEC_BASE_SIZE 8 // Abritrary small value
#define _Z_FRAME_VEC_SIZE_FROM_ZBUF_LEN(len) \
_Z_FRAME_VEC_BASE_SIZE + (len) / Z_CONFIG_FRAME_AVG_MSG_SIZE // Approximate number of messages in frame
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_Z_FRAME_VEC_BASE_SIZE + (len) / Z_CONFIG_FRAME_AVG_MSG_SIZE // Approximate number of messages in frame
(_Z_FRAME_VEC_BASE_SIZE + (len) / Z_CONFIG_FRAME_AVG_MSG_SIZE) // Approximate number of messages in frame

To avoid potential incorrect usage in expressions

@milyin milyin merged commit de430cb into eclipse-zenoh:dev/1.1.0 Nov 8, 2024
53 of 54 checks passed
jean-roland added a commit to jean-roland/zenoh-pico that referenced this pull request Nov 13, 2024
* feat: alias string decode

* fix: alias keyexpr only on rx buffer

* feat: add svec release function

* feat: remove duplicate message clear

* feat: remove unused subscription function

* fix: missing const qualifier

* feat: remove encoding null value

* feat: improve sample create perf

* feat: init string in encoding move

* feat: replace rc sub list with sub info vec

* feat: check before encoding clear

* feat: avoid rechecking msg reliability

* feat: add sub memoization

* fix: alias cache if suffix

* feat: move z_bytes instead of copy

* feat: add svec move function

* feat: add memoization config token

* feat: add vec alias function

* feat: switch sub cache to session level

* feat: add svec expand function

* fix: missing function args

* fix: don't use _z_noop_move in svec

* feat: svec ops return error instead of bool

* feat: svec functions

* feat: add use elem f in svec

* feat: switch frame nmsg to svec

* feat: add config value for initial frame size evaluation

* feat: remove superfluous init

* fix: rename cache token

* fix: remove superfluous initialization
@jean-roland jean-roland deleted the ft_frame_perf branch December 5, 2024 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Things could work better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants