GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — perf: stream potential tokens in OriginalSource, avoid discarded slices by alexander-akait · Pull Request #246 · webpack/webpack-sources Conversation
Member
Summary
This refactors This is the same class of fix as #240 (lookup-table token classification) and #226 (single-line Measured impactIn-process interleaved A/B (both lib versions loaded in one process, alternated each round so shared-host CPU drift cancels in the ratio; CPU = min/median over 80 rounds, allocation = single-call
Correctness
NotesI also prototyped extending the same idea to the non-final 🤖 Generated with Claude Code Generated by Claude Code
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsOriginalSource.streamChunks built the full splitIntoPotentialTokens array of substrings and iterated it, even though map()/sourceAndMap() run with finalSource:true and discard every chunk substring. Refactor splitIntoPotentialTokens into a streaming core eachPotentialToken that reports each token by [start,end) offset; the array-returning helper becomes a thin wrapper (its unit test and benchmark are unchanged). OriginalSource consumes the streaming core and slices only when a chunk is actually emitted — never on the final-source map/sourceAndMap paths. Measured (interleaved in-process A/B vs current main): OriginalSource.map() ~+15-18% CPU, -38..-46% allocation OriginalSource.sourceAndMap() ~+37-40% CPU, -38..-46% allocation streamChunks (slices needed) ~+30% CPU (no intermediate array) All 89,876 tests (incl. Fuzzy + 1373 snapshots) pass; output is byte-identical.
|
There was an error while loading. Please reload this page.
🦋 Changeset detectedLatest commit: 62d5e9b 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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@ ## main #246 +/- ## ========================================== + Coverage 98.11% 98.13% +0.01% ========================================== Files 25 25 Lines 2068 2089 +21 Branches 669 674 +5 ========================================== + Hits 2029 2050 +21 Misses 37 37 Partials 2 2
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:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Merging this PR will improve performance by 77.2%
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…sion) The previous commit turned the array-returning splitIntoPotentialTokens into a thin wrapper over eachPotentialToken, driving it with a per-token callback. CodSpeed flagged the helper's own benchmark regressing ~11-15% (instruction count): the callback indirection stops V8 inlining the slice/push of the hot scan. Restore the standalone direct loop for splitIntoPotentialTokens and keep eachPotentialToken separate for OriginalSource. They share only the small classification table, so there is no behavioural duplication. The OriginalSource map()/sourceAndMap() win is unchanged (it uses eachPotentialToken), and the helper benchmark is back to parity.
splitIntoPotentialTokens is now a standalone loop (production goes through eachPotentialToken), so its phase-2 end-of-string break and phase-3 newline branches were no longer exercised by the OriginalSource suite, dropping coverage. Add round-trip and branch-targeted cases so the helper is fully covered on its own.
5bbef09 to
8d47d1f
Compare
|
/easycla Generated by Claude Code |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
8d47d1f to
62d5e9b
Compare
ec58f39 to
62d5e9b
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This PR refactors OriginalSource.streamChunks to avoid allocating an intermediate token array and per-token substrings when finalSource: true (the dominant map() / sourceAndMap() paths), by streaming token boundaries via a new eachPotentialToken helper.
Changes:
eachPotentialToken(str, onToken) that reports [start, end) offsets and whether a token ends with \n.OriginalSource.streamChunks (columns-enabled path) to consume streamed token bounds and only slice substrings when a chunk is actually emitted.splitIntoPotentialTokens to cover phase-end edge cases (round-trip concatenation, trailing newline attachment, phase-2 end).Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/helpers-unit.js | Adds focused tests validating token concatenation/edge cases to guard the scanner behavior. |
| lib/OriginalSource.js | Switches from materialized token substrings to offset-streaming to avoid discarded allocations in finalSource mode. |
| lib/helpers/splitIntoPotentialTokens.js | Introduces eachPotentialToken streaming core while keeping the existing array-returning API intact. |
| .changeset/original-source-stream-potential-tokens.md | Adds a patch changeset describing the perf optimization and its impact. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.