Skip to content

Keep onData, onDataV2 and onWritable callbacks in MoveOnlyFunction inline storage - #1325

Open
nigrosimone wants to merge 1 commit into
uNetworking:masterfrom
nigrosimone:noexcept-persistent
Open

nigrosimone wants to merge 1 commit into
uNetworking:masterfrom
nigrosimone:noexcept-persistent

Conversation

@nigrosimone

Copy link
Copy Markdown

First part of #1300, only the NoexceptPersistent change.

v8::Global has a move constructor that is not noexcept, so every lambda that captures a UniquePersistent fails the is_small_object_v test in MoveOnlyFunction and is heap allocated, even when the capture is only 16 bytes (the handle plus the isolate pointer). That is one new and one delete per onData, onDataV2 and onWritable registration.

The fix is a small wrapper that restores the noexcept on the move (the underlying move is a pointer swap and cannot throw), used in those three sites. onAborted and collectBody capture more than 16 bytes and are left as they are.

Checked with a static_assert on ofats::any_detail::is_small_object_v for a lambda capturing UniquePersistent (false) and NoexceptPersistent (true), compiled with MSVC against the Node 26 headers.

@nigrosimone

Copy link
Copy Markdown
Author

Measured with the benchmark workflow proposed in #1326: this branch against master, both built on the same hosted runner, the load alternating between them (nigrosimone#2). Every row stays inside the noise band of the run, so at this resolution the change moves nothing in either direction, which is expected: one allocation per registration is well under a percent of a request.

Scenario Base req/s Head req/s Head / base Rounds Noise Busy CPU per request
http/hello-world 115910 114763 0.991x (-0.9%) 0.98 to 0.99 ±2.7% 100% / 100% 8.62 / 8.71 us (1.010x)
http/headers 96551 94921 0.986x (-1.4%) 0.98 to 0.99 ±3.5% 100% / 100% 10.36 / 10.54 us (1.014x)
http/json-post-1kb 53351 52818 0.985x (-1.5%) 0.97 to 1.00 ±5.3% 100% / 100% 18.76 / 18.94 us (1.016x)
http/cached 129466 128312 0.991x (-0.9%) 0.99 to 0.99 ±2.8% 100% / 100% 7.72 / 7.79 us (1.009x)
ws/echo-20b 119060 121176 1.018x (+1.8%) 1.01 to 1.03 ±1.1% 100% / 100% 8.39 / 8.25 us (0.982x)
ws/echo-4kb 103676 104278 1.003x (+0.3%) 0.99 to 1.01 ±1.8% 100% / 100% 9.64 / 9.58 us (0.998x)

"Noise" is how far base against base and head against head, the same code on both sides, got from 1.0 in the same run; a row is marked only when it moved more than that. Node v26.9.0, AMD EPYC 7763, 4 cores, wrk -t2 -c100.

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.

1 participant