Repository navigation
perf(core): NAPI and wasm bindings read through retrieve_data (LAB-12132) - #323
Conversation
0.7.5 adds ByteStorage::retrieve_data, which the bindings' read path needs, and raises the requirement so a fresh resolve cannot pick a core without it.
Both unpack paths called ByteStorage::retrieve and dropped the format String it allocates on every read. retrieve_data runs the same decode, checks and errors without that allocation, so the JS-visible value and error mapping are unchanged.
|
No actionable comments were generated in the recent review. Summary by CodeRabbit
WalkthroughThe TypeScript and WebAssembly bindings update their Changescachekit-core API update
Estimated code review effort: 2 (Simple) | ~8 minutes Change: Refactor Suggested reviewers: Merge Risk:
|
Code Review Completed! 🔥The code review was successfully completed based on your current configurations. Kody Guide: Usage and ConfigurationInteracting with Kody
Providing Context (Files & MCPs)Add these hints in your PR description (or a comment) to unlock deeper checks:
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
Kody Code Review — 1 suggested fix. 🛠️ Open Agent Prompt |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Instruction counts: PASSHead
All 41 workloads: 6 improved, 35 ok
|
Both bindings'
ByteStorage.unpacknow calls cachekit-core'sByteStorage::retrieve_datainstead ofretrieve.retrievereturns(data, format)and both bindings dropped the format, aStringallocated and freed on every read.retrieve_dataruns the same decode, checks and errors and skips that allocation (cachekit-io/cachekit-core#146). The JS-visible return value and error mapping are unchanged: the error still goes throughe.to_string()intoGenericFailure(NAPI) andJsError(wasm).retrieve_datafirst ships in cachekit-core 0.7.5, so both crates now requirecachekit-core = "0.7.5"(was"0.7.0"), and a fresh resolve cannot pick a core without it.Commits
perf(deps): bump cachekit-core to 0.7.5:Cargo.tomlrequirement and lock in both crates. Onlycachekit-coremoved in either lock (0.7.4 → 0.7.5,cargo update -p cachekit-core --precise 0.7.5). 0.7.5 also rewrites the core's store of envelopes under 64 B (cachekit-io/cachekit-core#148) and decodes the envelope in one bounded pass on retrieve (cachekit-io/cachekit-core#150), so this commit moves both halves of an envelope round trip on its own.perf(core): read through retrieve_data in the NAPI and wasm bindings: the two call sites, plus the two docs that name the read call (SECURITY.md, the header oftest/protocol/decode-bounds.protocol.test.ts).Measurement
Instructions per op from
bench/ir.mjson three builds, so the call swap is measured apart from the version bump:main(core 0.7.4,retrieve)retrieve)retrieve_data)The workloads are the existing envelope ones: one
packplus oneunpackper op, at 40 B (*-envelope-40b) and 1,055 B of msgpack (*-envelope).packis the same code in b and c, so the b → c delta is the read alone.napi-envelope-40bnapi-envelope(1,055 B)wasm-envelope-40bwasm-envelope(1,055 B)A/A floor: each cell is the median of 5 repeats, and the largest spread, (max − min) / median, across all 12 cells is 0.0039% (
wasm-envelopeon b, about 2 Ir/op). The smallest swap delta, −223 Ir/op, is about 100× that. Build c measured the same Ir/op in two separate runs (once against b, once against a).Run with Node 24.21.0, valgrind 3.22.0, linux-x64,
ir.mjs --only napi-envelope,napi-envelope-40b,wasm-envelope,wasm-envelope-40b --jobs 4, each tree a separate worktree outside this checkout at paths of equal length, built withpnpm buildandbuild:wasm; the three build hashes differ. This PR's Instruction counts check measures a → c on GitHub-hosted runners.Sibling paths
Store and retrieve: only retrieve changes;
packalready callsstorewith no format to discard. NAPI and wasm: both change.validatecallsByteStorage::validate, which in 0.7.5 is alreadyretrieve_data(..).is_ok(), so it stays.Tests
pnpm lint,pnpm type-check,pnpm type-check:tests: pass.pnpm testagainst the NAPI binding built from this head: 2,893 passed, 1 skipped. That includes the 92 decode-bounds protocol vectors through the NAPIunpack.pnpm --filter @cachekit-io/cachekit test:workersagainst the wasm binding built from this head: 307 passed, which runs the same decode-bounds vectors through the wasmunpackinside workerd.cargo clippy --release -- -D warnings: clean on both crates (wasm32 target for core-wasm).cargo fmt --check: clean on core-ts, the crate the pre-commit hook checks.Docs
SECURITY.mdand the decode-bounds test header namedByteStorage::retrieveas the read call; both now nameretrieve_data. The test header also now describes 0.7.5's decode: lengths checked against the input in one pass, with the pre-scan for any envelope that pass declines. The decompression boundSECURITY.mdstates is unchanged in 0.7.5. No README or API doc names the call.Closes LAB-12132