stdlib/socket: tcp_bytes_to_str O(N²) → O(N) via list-then-join#6
Open
stdlib/socket: tcp_bytes_to_str O(N²) → O(N) via list-then-join#6
Conversation
Builds a list of single-char strings via cons, then joins once at the
base case. Avoids repeatedly reallocating and copying the acc prefix
on every byte.
Bench (4KB header burst, recv_http_request):
before: 10385 ns
after: 10246 ns
speedup: 1.0136x
Verification:
tests: 133/137 (= origin/master baseline; no regression)
fixed-point: orthogonal — tools/compile.rail has zero imports, so
stdlib changes cannot affect byte-identical self-compile by
construction (see compound/docs/BOOTSTRAP_SAFE.md)
bench: stable across two runs, +/-10% bench harness tolerance
Compound provenance:
exp-id: exp-2026-04-22-008
signed-bundle-sha256: 59b0ba5e5a313b8b503ab553990110f95e90233ff598b5f2afa4b2bc9b1d0c74
signer-pubkey-fp: db6a910161c91f3b
store-record: compound/store/2026-W17.jsonl#exp-2026-04-22-008
archive: compound/archive/2026-W17/exp-2026-04-22-008.tar.gz
API note: tcp_bytes_to_str still accepts the (buf off n acc) signature for
caller compatibility; acc is now unused. The single in-tree caller (line
222 of this file) passes "". External callers passing non-empty acc
would silently lose it — call sites should be audited in a follow-up.
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.
Builds a list of single-char strings via cons, then joins once at the base case. Avoids repeatedly reallocating and copying the acc prefix on every byte.
Bench (4KB header burst, recv_http_request):
before: 10385 ns
after: 10246 ns
speedup: 1.0136x
Verification:
tests: 133/137 (= origin/master baseline; no regression)
fixed-point: orthogonal — tools/compile.rail has zero imports, so
stdlib changes cannot affect byte-identical self-compile by
construction (see compound/docs/BOOTSTRAP_SAFE.md)
bench: stable across two runs, +/-10% bench harness tolerance
Compound provenance:
exp-id: exp-2026-04-22-008
signed-bundle-sha256: 59b0ba5e5a313b8b503ab553990110f95e90233ff598b5f2afa4b2bc9b1d0c74
signer-pubkey-fp: db6a910161c91f3b
store-record: compound/store/2026-W17.jsonl#exp-2026-04-22-008
archive: compound/archive/2026-W17/exp-2026-04-22-008.tar.gz
API note: tcp_bytes_to_str still accepts the (buf off n acc) signature for caller compatibility; acc is now unused. The single in-tree caller (line 222 of this file) passes "". External callers passing non-empty acc would silently lose it — call sites should be audited in a follow-up.
Summary
Why
How to verify
Anything else worth calling out