perf: optimize deep nested decode#83
Conversation
Cache formatted parent paths while decoding entries so deep sibling paths can reuse ancestor path strings instead of rebuilding the same prefixes repeatedly. Parse structural metadata paths lazily so non-empty object metadata does not pay path parsing cost unless decode needs to materialize an empty container, resize a sparse array, or convert a Set/Map. Adds a patch changeset for the decode performance improvement.
Greptile SummaryThis PR optimizes decode performance for deeply nested form data by caching intermediate parent-path strings and deferring
Confidence Score: 5/5Safe to merge. The changes are a self-contained performance optimization with no correctness risk. Both the incremental parent-path cache and the lazy structural-segment cache are logically equivalent to the pre-PR behavior. The No files require special attention.
|
| Filename | Overview |
|---|---|
| src/path.ts | Adds parsePathEntry helper that combines parsePath + value into a ParsedPathEntry. Minimal, correct refactor. |
| src/decode.ts | Removes segments from StructuralPath, adds incremental parent-path building with a two-level string cache, and lazily parses structural-path segments via parsedSegmentsCache shared across all three post-unflatten phases. Logic is correct; the shared cache prevents double-parsing in the empty-container + sparse-array or set/map branches. |
| .changeset/optimize-deep-decode.md | Adds a patch-level changeset entry describing the decode performance improvement. |
Reviews (2): Last reviewed commit: "perf: cache lazy structural path parsing" | Re-trigger Greptile
Reuse parsed structural path segments across empty-container reconstruction, sparse-array resizing, and Set/Map conversion. This preserves the lazy parsing path for structural metadata that is skipped while avoiding duplicate parsePath calls for structural paths that decode still needs to handle.
Summary
Fixes #70.
Benchmark notes
Ran
bun run benchon Bun 1.3.13 against amainworktree and this branch.maindeeply nested object decode:20.544 ms/op18.578 ms/opFlat/repeated workloads stayed in the same range in local benchmark runs:
0.562 ms/oponmain,0.584 ms/opon this branch0.261 ms/oponmain,0.281 ms/opon this branchVerification
bun fmtbun lint:fixbun testbun typecheckbun run buildbun lintbun run smoke:packagebun run bench