Skip to content

perf(value): construct byte arrays directly - #398

Open
tvolk131 wants to merge 1 commit into
BlockstreamResearch:masterfrom
tvolk131:perf/direct-byte-array
Open

tvolk131 wants to merge 1 commit into
BlockstreamResearch:masterfrom
tvolk131:perf/direct-byte-array

Conversation

@tvolk131

@tvolk131 tvolk131 commented Oct 25, 2026 •

Copy link
Copy Markdown

Value::from_byte_array builds intermediate byte values and products, repeatedly allocating buffers and copying bits. Construct one Arc<[u8]> instead, using the cached balanced word type. Beyond the cache, construct only the missing type levels.

A warmed release microbenchmark on macOS ARM64 with Rust 1.99 measured 32-byte construction at 5.06 µs before and 26.4 ns after, with allocations reduced from 131 to 1 (33 paired CPU-time samples; allocation counts measured separately). These are constructor measurements, not application speedups.

Additional local differential checks matched master for 67,640 arrays, including every one-byte and two-byte value and larger cases through 16 KiB.

Validation:

  • cargo test --locked --workspace --all-features (123 library tests, 14 sys tests, 2 doctests)
  • cargo test --locked -p simplicity-lang --lib --no-default-features (67 tests)
  • cargo +1.74.0 test --offline --locked -p simplicity-lang --lib --all-features (123 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.

@tvolk131

Copy link
Copy Markdown
Author

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

@tvolk131
tvolk131 force-pushed the perf/direct-byte-array branch 3 times, most recently from d688d1e to 1a31aeb Compare October 26, 2026 03:18
Construct one byte buffer and use the cached balanced word type. For widths beyond the cache, extend only the type metadata by taking products of identical halves instead of constructing intermediate values and copying bits. Preserve the power-of-two length assertion.

Cover bytes, compact encoding, product views, fixed-width constructors, invalid lengths and cached/uncached type boundaries.

Written by OpenAI Codex.

Written with GPT 6.1 Sol on Extra High.
@tvolk131
tvolk131 force-pushed the perf/direct-byte-array branch from 1a31aeb to 9bba012 Compare October 26, 2026 03:28
@tvolk131
tvolk131 marked this pull request as ready for review October 26, 2026 03:40
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