Repository navigation
feat: add exact decoded length and validation APIs - #22
Open
patrickZWY wants to merge 4 commits into
Open
patrickZWY wants to merge 4 commits into
patrickZWY wants to merge 4 commits into
Conversation
Co-authored-by: Codex <noreply@openai.com>
This reverts commit e59a6f3.
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.
Summary
Add two allocation-free methods to Codec and concrete Base16, Base32 and Base64 profiles:
Closes #12.
Design Notes
Thresholds use encoded complete-prefix bytes. Scalar checks use short loops or eight-byte lookup batches. All paths preserve decoding error precedence and original byte offsets. SIMD reads are bounded; no decoded output is allocated or written.
Performance Evidence
Compared scalar/SIMD paths, 2/4/8/16-vector batches, thresholds, alignment and tails. macOS sampling and disassembly guided classification and batching changes. Experimental tools remain outside this PR.
Method: rustc 1.100.0 / LLVM 23.1.5, thin LTO, one codegen unit; matched inputs, lockfile, rounds and executable paths. Six order-balanced samples per candidate; five interleaved peer samples. No allocation in repeated loops. Tables report median batch milliseconds; lower is better within each row. Initial SIMD is an earlier validation prototype, not main. Candidates include their dispatch and error-recovery paths.
Environment: Mac i5-8279U, no affinity; Ubuntu i5-1230U, pinned P-core 0/E-core 4, powersave governor, no fixed frequency or SMT isolation.
Interpretation (lowest observed medians): The 16-vector candidate wins the Mac/E-core mixed-valid rows and the Mac 1 MiB row. Eight vectors win the P-core mixed-valid row; initial SIMD wins all three offset-64 rejection rows. We choose eight vectors for the throughput/recovery trade-off: mixed-valid time is 20-31% below initial SIMD, while rejection time is 16-36% below the 16-vector candidate in the displayed cases.
Mixed pool: 200 messages, 60% 8 B / 20% 32 B / 10% 1 KiB / 10% 16 KiB. Sizes are raw bytes; offsets are encoded bytes. Current ecosystem comparison (base64-simd 0.8.0):
Interpretation (lowest observed medians): Bases check wins on the P-core, using 5.5% less time than base64-simd. base64-simd wins on the E-core, using 9.8% less time than Bases check. Bases check uses 60-62% less time than full Bases decoding on both cores. The validators have different error-reporting contracts, as noted below.
Decoder integration follow-up (benchmark-only)
Compared the existing SIMD decoder at this PR's
a71dae2with three isolated prototypes: validate first then decode without repeating SIMD validation, or fuse error checks across four/eight vectors. The classifier is already shared in the PR baseline; this measures additional batching, not an upgrade from scalar decoding. No experimental implementation, harness or result files are included in this PR.Screened 39 deterministic scenarios with eight order-balanced samples per version on Mac and each Ubuntu core, including buffer/owned/uninitialized/in-place output, URL profiles, alignment, rejection and mixed messages. Source, harness, lockfile, compiler and release settings matched across variants; native binary hashes were verified. Fixture setup and reusable-buffer allocation were excluded; owned allocation/drop and in-place input restoration were included. Builds/tests/disassembly finished before timing; Ubuntu cores ran sequentially.
P-core variability prompted separate confirmation of nine scenarios: baseline versus each fused decoder, 16 alternating ABBA/BAAB blocks per pair/core, 32 samples per version/pair, approximately 50 ms baseline samples and equal fixed rounds. The table reports the median of within-block candidate/baseline mean-time ratios as elapsed-time changes; negative is faster. All samples/outliers were retained, with screening and confirmation analyzed separately.
For a 1 KiB message with
!at encoded offset 256, rejection took 2.88x/2.20x the baseline with four vectors and 6.01x/4.20x with eight (P-core/E-core); every confirmation block was slower. The fused prototypes recover the first error by scalar-scanning the failed batch, so this does not establish a lower bound for SIMD error recovery. The separate validate-then-decode prototype also showed no consistent cross-platform advantage; initial 1 MiB elapsed times increased 22.8% on Mac and about 11% on both Ubuntu cores.The results support keeping batching specific to the validation workload in this PR. Full decoding still performs value conversion, bit packing and output stores; eight-vector fusion also introduced vector stack accesses in both platforms' assembly. These are code/disassembly observations, not hardware-counter attribution. The earlier
checkversusdecodetable compares different work and cannot be used as a decomposition of decoder cost. Further SIMD error-recovery improvements remain unmeasured.Validation
cargo x test(715 executions per candidate/platform) on Mac and Ubuntu, all 209 existing benchmark output checks, and additional independent-alphabet/wire-byte, first-error, batch-boundary, in-place/uninitialized-output and buffer-canary checks. These prototype checks are separate from validation of the committed PR code.Formal verification
--no-cheating,a71dae2) verifies sizing/overflow, Base16/32/64 structural plan acceptance, scalar/tail initialization, Base64 packing, and explicit SIMD bounds/alignment, append/in-place/streaming models. Latest evidence adds Base32 tail bytes/error precedence, an ASCII word projection, and initialization-to-array/append adapters (20 checks, 0 errors).Considerations