Skip to content

stdlib/socket: tcp_bytes_to_str O(N²) → O(N) via list-then-join#6

Open
zemo-g wants to merge 1 commit intomasterfrom
compound/exp-008-bytes_to_str
Open

stdlib/socket: tcp_bytes_to_str O(N²) → O(N) via list-then-join#6
zemo-g wants to merge 1 commit intomasterfrom
compound/exp-008-bytes_to_str

Conversation

@zemo-g
Copy link
Copy Markdown
Owner

@zemo-g zemo-g commented Apr 26, 2026

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

./rail_native test                     # 116/116
./rail_native self && cmp rail_native /tmp/rail_self   # fixed point
# plus any module-specific tests

Anything else worth calling out

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.
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