Repository navigation
perf(downgrader): build map output directly instead of via Object.fromEntries - #94
Conversation
…mEntries `map` collected `[key, value]` pairs and then called `Object.fromEntries`. Writing each entry straight into the output object with `setOwn` skips the pair arrays and the second pass. `setOwn` already keeps a `__proto__` key as an own property, and key order is unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ybYkXeGezZAgSErMANBtg
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
mapbuilds output directly —packages/downgrader/src/shared.tsnow writes each converted entry into a plainRecordviasetOwninstead of collecting pairs and callingObject.fromEntries, matching the existingconvertObject/copypattern.__proto__test strengthened — thekeeps own __proto__ keys as keystest now also places an integer key beside__proto__and pins key order (['1','__proto__']) and the normal prototype.
The two paths are equivalent: Object.fromEntries also defines own data properties, so __proto__ was already handled as an own key, and integer-index enumeration order is spec-defined independently of insertion order. out was already a fresh local object, so returning it directly adds no aliasing. No concerns.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
Merging this PR will improve performance by 13.3%1 warning
Performance Changes
Tip Curious why performance improved? Comment Comparing |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |

Requested by dinwwwh · project thread
What
mapinpackages/downgrader/src/shared.tscollected[key, value]pairs and then calledObject.fromEntries(since #50). It now writes each entry straight into{}withsetOwn, the same wayconvertObjectandcopyalready do.setOwnkeeps a__proto__key as an own property, and key order is unchanged.The existing
__proto__test inv3.1-to-v3.0.test.tsnow also puts an integer key beside__proto__in apropertiesmap and checks the key order and that the map keeps a normal prototype. It fails ifmapuses a plainout[key] = converted.Measurements
Wall time with the JIT, median of shuffled rounds with gc between runs:
Output is byte-identical on 67 real docs and 800 fuzzed docs. 254 tests and
pnpm run checkpass.Generated by Claude Code