Repository navigation
perf: make lending buffers per event cheap again - #106
Merged
Merged
Conversation
Lending buffers per event (#101) added about 820 user-space instructions to every event on V 0.5.2: array pop and push, empty-array literals, and the calls to lend, settle and give_back. That is +35% on a WebSocket echo and +8% on a keep-alive request (callgrind on hostlab). The pools are now a stack written through a pointer, so a move is a plain struct copy, and the per-event functions are inlined. Instructions per WebSocket echo go from 3110 to 2616 (-16%) and per baseline request from 10763 to 10270 (-4.6%). Memory is unchanged: the buffers still go back after each event.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The HttpArena run of v1.13.1 (MDA2AV/HttpArena#1660) came back lower than the v1.10.0 run on some profiles. I measured where that comes from.
What the drop is
hostlab's wall-clock numbers are too noisy to see a few percent, so I counted user-space instructions with callgrind instead. The count is deterministic. The server is pinned to 4 cores and the load comes from the other 4; startup is excluded.
The change
V 0.5.2's
pop(),<<, array element stores and[]u8{}each go through a runtime call and amemcpyof the array header. Lend and settle did several of them per event, plus three calls of their own.BufPoolis a stack whose slots are written through a pointer, so a move is a plain struct copy. The slot array only grows, on the cold path.[]u8{}.lend,settle,give_backandLoop.settleare@[inline].This removes about 500 of the 820 instructions. Memory is unchanged: buffers still go back to the pool after every event.
Two things I tried and dropped: storing slots with
bufs[n] = bgained nothing, becausearray_sethas the samememcpy. Avoiding the pointer locals that V pins withGC_reachable_heregained 3 instructions.Checks
All on hostlab:
hotpath_lint,gcpin_check, the six examples) passes with 0 warnings.v fmt -verifyis clean.BufPoolhas noarray__cloneormemdup.