perf(silkd): memchr the session sentinel scan (~26x)#16
Merged
Conversation
converse scanned each ~32KB accumulated output chunk for the unpredictable command marker with a naive windows().position() byte-walk. That is ~37.8us per 32KB scan — more than the base64 encode of the same bytes — and it runs once per read, so a large-output session command (a build, a verbose log) pays it on every chunk. memchr::memmem::find does the same search with SIMD first-byte skipping at ~1.4us/32KB (~26x). Only the session path uses this scan; plain exec is unaffected.
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.
A persistent-shell (
session) command's output is delimited by an unpredictable__SILK_<32hex>__sentinel.conversescanned each accumulated ~32KB output chunk for it with a hand-rolledhaystack.windows(needle.len()).position(|w| w == needle)byte-walk, once per read. For a session command with large output (a build, a verbose log), that scan runs on every 32KB chunk.Measurement (isolated, M2 Max)
Scanning a 32KB no-match buffer for the 41-byte marker:
windows().position()memchr::memmem::find37.8µs/32KB is more than the base64 encode of the same bytes (~15µs) — so on a large-output session command the sentinel scan was a larger per-chunk cost than the base64 the perf sweep had assumed dominated. For a 200MB session command (~6100 chunks) the scans alone drop from ~230ms to ~9ms.
Change
Replace the naive
findwithmemchr::memmem::find(SIMD first-byte skipping);memchrwas already in the lock tree viaregex, now a direct dep. Only the session path uses this scan — plainexecis unaffected (it frames on the exit protocol, not a sentinel).Gates
fmt --check✓,clippy --all-targets -D warnings✓,cargo test✓.rust:1-slimcontainer, fixtures + git):clippy✓,cargo test✓ (18/18 incl. the session round-trip tests that driveconverse).