Skip to content

perf(value): avoid an unused byte in padded decoding - #399

Open
tvolk131 wants to merge 1 commit into
BlockstreamResearch:masterfrom
tvolk131:perf/skip-padded-trailing-byte
Open

tvolk131 wants to merge 1 commit into
BlockstreamResearch:masterfrom
tvolk131:perf/skip-padded-trailing-byte

Conversation

@tvolk131

@tvolk131 tvolk131 commented Oct 25, 2026 •

Copy link
Copy Markdown

Value::from_padded_bits always appends a final byte, even when all bits fit in complete bytes (including zero-width values). For byte-aligned values within the initial allocation cap this exceeds the reserved capacity, triggering a reallocation and retaining an unused zero byte. Only append a partial byte when the bit width has a remainder.

Warmed release-mode measurements on macOS ARM64 with Rust 1.99 eliminated one reallocation per aligned decode. The initial 33-pair CPU benchmark measured 64-bit decoding at 76.4 ns before and 64.0 ns after (about 19% less CPU time). Larger values showed a smaller, noisier benefit; this is an isolated decoding measurement.

Extend the existing round-trip test to cover unit, partial-byte, aligned, and optional values at every starting bit offset; check exact backing bytes, consumed bits, and truncated inputs.

Validation:

  • cargo test --locked --workspace --all-features (120 library tests, 14 sys tests, 2 doctests)
  • cargo test --locked -p simplicity-lang --lib --no-default-features (64 tests)
  • cargo +1.74.0 test --offline --locked -p simplicity-lang --lib --all-features (120 tests)
  • cargo fmt --all -- --check
  • cargo clippy --locked --workspace --all-targets --all-features -- --deny warnings

Written by OpenAI Codex.

Written with GPT 6.1 Sol on Extra High.

@apoelstra

apoelstra commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Hey Tommy, thanks for the contribution! Can you say what would be required to undraft this. (Even "Draft until I finish iterating on it" would be fine; the point is just so reviewers know whether they should ignore the PR, and if so, for how long.) Same with your other PRs.

@apoelstra

apoelstra commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Also, could you say what model you used, and what reasoning level (if you know/remember)?

(I'd like to update our AGENTS.md to request this information, and eventually to just mandate that any LLM-generated PRs use large and/or new models. I would also like to know the model size and quantization, though my guess is that no OAI/Anthropic model will answer that request :P)

@tvolk131

Copy link
Copy Markdown
Author

Draft until I finish iterating on it and hand-read & hand-test the code

@tvolk131

Copy link
Copy Markdown
Author

Real Tommy here (weird that this kind of needs to be said these days).

could you say what model you used, and what reasoning level (if you know/remember)?

Will do!

I would also like to know the model size and quantization, though my guess is that no OAI/Anthropic model will answer that request

Haha yeah unlikely :/

Hope the draft PRs aren't too spammy, I'll make sure to review and undraft or close them quickly.

@apoelstra

Copy link
Copy Markdown
Collaborator

No, I think they're fine. I just check them to see whether they're drafted due to being blocked on some other PR, in which case I'll prioritize that, and otherwise ignore them :).

Only append a partial byte when one exists, avoiding an unnecessary reallocation and unused byte for byte-aligned or zero-width values. Extend padded round-trip coverage to offsets, storage size and truncated inputs.

Written by OpenAI Codex.
@tvolk131
tvolk131 force-pushed the perf/skip-padded-trailing-byte branch from df6b61c to d424b71 Compare October 26, 2026 03:44
@tvolk131
tvolk131 marked this pull request as ready for review October 26, 2026 04:11
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.

2 participants