Skip to content

perf: split Publisher::send() into separate prefix/value parts - #141

Merged
jasonk000 merged 2 commits into
Netflix:sn-proxyd-forkfrom
akonradi:elide-dup-prefix-copy
Oct 7, 2026
Merged

jasonk000 merged 2 commits into
Netflix:sn-proxyd-forkfrom
akonradi:elide-dup-prefix-copy

Conversation

@akonradi

@akonradi akonradi commented Oct 6, 2026

Copy link
Copy Markdown

Avoids a redundant copy: the previous code assembled a complete 'prefix+value' line in a thread-local scratch std::string, then copied that whole line into the Unix-domain transport's accumulation buffer -- the prefix got copied twice per measurement. Publisher::send() now takes the cached per-meter prefix and the freshly-formatted value as two separate string_view parts; the Unix-domain sender appends each straight into its own buffer_, so the prefix is copied into its final resting place exactly once. StatelessMeter::send()/send_uint() format the value directly into a plain stack array (no thread-local std::string staging buffer needed at all now, since there's no longer a combined line to assemble) and pass it on as a view.

UDP sends the two parts as one datagram via a 2-buffer asio scatter/gather write -- no scaling concern there, since each UDP send is always exactly these two buffers, never batched with others the way Unix-domain measurements are.

No change to the public Id/Tags/Counter/Gauge/.../Registry API.

Microbenchmark (300 Counters, 500K Increment() calls, real Unix-domain receiver): ~0.050us/call vs baseline's ~0.056us/call, ~10% faster

@akonradi

akonradi commented Oct 6, 2026

Copy link
Copy Markdown
Author

cc @jasonk000

@jasonk000

Copy link
Copy Markdown
Member

@akonradi looks like a rebase should fix the build issue, can you try that? thx

@jasonk000 jasonk000 mentioned this pull request Oct 7, 2026
Avoids a redundant copy: the previous code assembled a complete
'prefix+value' line in a thread-local scratch std::string, then copied
that whole line into the Unix-domain transport's accumulation buffer --
the prefix got copied twice per measurement. Publisher::send() now takes
the cached per-meter prefix and the freshly-formatted value as two
separate string_view parts; the Unix-domain sender appends each straight
into its own buffer_, so the prefix is copied into its final resting
place exactly once. StatelessMeter::send()/send_uint() format the value
directly into a plain stack array (no thread-local std::string staging
buffer needed at all now, since there's no longer a combined line to
assemble) and pass it on as a view.

UDP sends the two parts as one datagram via a 2-buffer asio scatter/gather
write -- no scaling concern there, since each UDP send is always exactly
these two buffers, never batched with others the way Unix-domain
measurements are.

No change to the public Id/Tags/Counter/Gauge/.../Registry API.

Microbenchmark (300 Counters, 500K Increment() calls, real Unix-domain
receiver): ~0.050us/call vs baseline's ~0.056us/call, ~10% faster
@akonradi
akonradi force-pushed the elide-dup-prefix-copy branch from 2cd6ac1 to f826281 Compare October 7, 2026 17:51

@jasonk000 jasonk000 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A couple of suggestions.

Comment thread spectator/publisher.h
Comment thread spectator/stateless_meters.h Outdated
@jasonk000
jasonk000 merged commit 6e5f85e into Netflix:sn-proxyd-fork Oct 7, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants