Repository navigation
Conversation
Replace the EventStream JavaScript CRC32 loop with the native Bun primitive while preserving wire validation and seeded byte-view semantics. Co-authored-by: luvs01 <[email protected]>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
✅ Deterministic PR hygiene checks passed. |
|
The reviewed change at commit |
Summary
Kiro's production receive path validates two CRC32 checksums for every AWS EventStream frame. The decoder currently builds a 256-entry lookup table and walks every byte in JavaScript. Replace that loop with
Bun.hash.crc32(bytes, seed >>> 0), preserving the exported helper, unsigned IEEE CRC32 result, seed continuation/coercion, and the exact offset byte view.The framing and corruption/size checks stay in place. Fixed vectors, independently generated wire bytes, offset views, incremental seeds, and malformed-frame tests cover the contract. The transport inventory documents the native checksum dependency, and the original framing-code attribution is retained.
Bun 1.4.4's release notes describe faster native hash paths. CRC32 was already available in 1.4.3; this is an application-level replacement of a custom implementation, not a claim that the API is new in 1.4.4. The measurements below use byte frames from this repository instead of extrapolating the blog's short-string benchmark.
Measured effect
Linux x86_64, official Bun 1.4.4 (
38afee6c8), baselinec4d4bb2da2162e23c314befafc5ec104292902a0. The benchmark imports the actual baseline and final PR modules separately, checks identical wire bytes and decoded values, warms each operation, alternates execution order, and reports the median of seven runs.These are synthetic EventStream framing measurements, not end-to-end request or model-response improvements. Kiro is the current production decoder consumer.
encodeMessageis a test/fixture helper; its measured speedups (1.43x, 3.35x, 16.06x for the same sizes) are not production upload gains. There are no timing assertions in the test suite.Verification
Using the official executables, with the matching binary directory on PATH:
bun scripts/test.ts ./tests/responses/eventstream-decoder.test.ts ./tests/providers/kiro/kiro-stream.test.ts ./tests/providers/kiro/kiro-transport-parity.test.ts— 150 pass, 0 fail, 536 assertions.bun test ./tests/responses/eventstream-decoder.test.ts ./tests/providers/kiro/kiro-stream.test.ts ./tests/providers/kiro/kiro-transport-parity.test.ts— 150 pass, 0 fail, 536 assertions.bun run test:changed --parallel=2 ./tests/providers/kiro/— 350 pass, 0 fail across 13 selected files, 1,391 assertions.bun run typecheck,bun run structure:check,bun run privacy:scan,bun scripts/file-size-ratchet.ts, andgit diff --cached --check— passed.Full-suite scope exception: the approximately 2,600-file repository suite was not run locally because of the constrained shared environment and concurrent worktrees. Focused codec regressions and import-connected Kiro behavior were run instead, as allowed by
AGENTS.md. Repository-wide and macOS/Windows execution remain for CI/maintainer validation. Public wire behavior and configuration are unchanged; no docs-site workflow update is required.Reproduce the framing benchmark
Save the following as a temporary TypeScript file. Run it with Bun 1.4.4, passing absolute paths to
src/lib/eventstream-decoder.tsin a baseline checkout at the commit above and in this PR checkout:Checklist
Security review: checksum validation still rejects corrupt input, frame/header bounds remain intact, and no authentication, credential handling, network destinations, or logging were added.
Co-authored-by: luvs01 [email protected]