perf: avoid Buffer.isBuffer call on deserialize hot path#21203
Conversation
🦋 Changeset detectedLatest commit: 5ddfa0e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This PR is packaged and the instant preview is available (f960917). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@f960917
yarn add -D webpack@https://pkg.pr.new/webpack@f960917
pnpm add -D webpack@https://pkg.pr.new/webpack@f960917 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21203 +/- ##
==========================================
+ Coverage 92.69% 92.71% +0.02%
==========================================
Files 588 589 +1
Lines 64122 64190 +68
Branches 17799 17806 +7
==========================================
+ Hits 59435 59514 +79
+ Misses 4687 4676 -11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will improve performance by ×2.3
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Memory | benchmark "many-modules-esm", scenario '{"name":"mode-production","mode":"production"}' |
7.3 MB | 9.3 MB | -21.02% |
| ⚡ | Memory | benchmark "lodash", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
859.1 KB | 133 KB | ×6.5 |
| ⚡ | Memory | benchmark "asset-modules-inline", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
1,294.3 KB | 324.1 KB | ×4 |
| ⚡ | Memory | benchmark "react", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
340.1 KB | 154.3 KB | ×2.2 |
| ⚡ | Memory | benchmark "side-effects-reexport", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
1,204.1 KB | 762.7 KB | +57.89% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing perf-isbuffer (5ddfa0e) with main (80f5ed8)
Summary
What kind of change does this PR introduce?
In ObjectMiddleware's decodeValue deserialize hot path, replace Buffer.isBuffer(item) with typeof item === "object". The preceding item === ESCAPE (null) branch is taken first, and the serializer never emits a live non-null object other than a Buffer into the stream (plain objects/Maps/Sets are decomposed into ESCAPE markers + primitive fields), so the two checks are equivalent — but typeof avoids a function call per non-string primitive (~1.8× faster in a micro-benchmark on a mixed value stream).
Did you add tests for your changes?
No
Does this PR introduce a breaking change?
No
If relevant, what needs to be documented once your changes are merged or what have you already documented?
n/a
Use of AI
Yes