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 throughput performance (trigger local subscriber focus) #730

Merged
merged 13 commits into from
Oct 11, 2024

Conversation

jean-roland
Copy link
Contributor

@jean-roland jean-roland commented Oct 10, 2024

There is a small performance dip in non-fragment peer throughput compared with 0.11. Profiling helped identify a much longer time spent in trigger_local_subscriberand this PR aims to fix this.

  • Static inline functions:
    Functions that should have been inlined by the compiler (like z_sample_null) weren't. This is solved by explicitly setting all the _null, _check and _alias functions to static inline.

  • Null functions:
    A lot of time was spent initializing types to 0 compared to just using memset(0), switching all the _null functions to a {0} initialization closed this gap and is less prone to error.

  • Slice init / string preallocate:
    This functions had many superfluous checks / init. They got simplified.

  • get_expanded_key_by_key:
    Added a shorter path for already expanded keys.

  • trigger_local_subcriber:
    Added a shorter path when there is 0 subscribers to trigger.
    Added a config token, off by default, to execute this function.

The fastest code is the one we don't execute

Copy link

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

@jean-roland jean-roland added the enhancement Things could work better label Oct 10, 2024
@DenisBiryukov91
Copy link
Contributor

Looks good, but I do not really like the idea of memsetting everything to 0, especially for dependent structs. In case we modify null-constructors for their fields, we risk to face some difficult to detect bugs.
I'm wondering if memsetting to 0 really provides a speed boost that is worth the cost.

@jean-roland
Copy link
Contributor Author

I understand the issue, but then maybe we should make a distinction between _null which would be some kind of memory initialization and _init that would be a type initialization, in the case where those two operations are different.

If we distinguish the two then, I believe the performance increase won't cause problems.

@jean-roland jean-roland changed the base branch from main to dev/1.1.0 October 11, 2024 13:47
Copy link
Member

@sashacmc sashacmc left a comment

Choose a reason for hiding this comment

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

Small note, others LGTM

src/net/reply.c Outdated
@@ -49,13 +40,13 @@ void _z_reply_data_free(_z_reply_data_t **reply_data) {

z_result_t _z_reply_data_copy(_z_reply_data_t *dst, const _z_reply_data_t *src) {
*dst = _z_reply_data_null();
dst->_tag = src->_tag;
Copy link
Member

Choose a reason for hiding this comment

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

What the reason of this change?
In case of error will be nice to avoid unnecessary dst changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah so "no data" value of tag is 3 and not 0 so I was trying to avoid a reply_data_init function, but I guess that won't be avoided.

@jean-roland jean-roland force-pushed the test_perf branch 3 times, most recently from e06a1cb to 29f592a Compare October 11, 2024 15:42
@milyin milyin merged commit f8df508 into eclipse-zenoh:dev/1.1.0 Oct 11, 2024
53 of 54 checks passed
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.

4 participants