Repository navigation
perf(concat): avoid repeatedly copying accumulated results - #2132
Open
chaser940428-pixel wants to merge 2 commits into
Open
chaser940428-pixel wants to merge 2 commits into
chaser940428-pixel wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and change
concatLimitcurrently callsresult.concat(...mapResults[i])for every completed item. This copies the entire accumulated prefix each time. When many iteratees each return a small array, aggregation does quadratic copying after the async work is already done.Append each batch at an offset in the output instead. Keep native
[].concat(...args)for each individual batch so variadic results, one-level flattening andSymbol.isConcatSpreadablekeep their existing behavior. Extend the output length and copy only present indices, preserving sparse holes without walking their empty ranges. The shared path coversconcat,concatLimitandconcatSeries.Add 12 compatibility cases across those three APIs (sparse results, spreadability/nesting, variadic falsy values and Promise results), plus a small standalone
perf/concat-aggregation.jsbenchmark. No timing threshold is added to unit tests. The compatibility cases protect existing behavior; they are not claimed as previously failing correctness tests.Validation
Windows / Node 24.22.1:
npm test: 715 passing, including the new compatibility cases; lint passes.git diff --check: passes.BABEL_CACHE_PATH; the initial default-home cache write was denied by the execution environment. No test assertion or timeout was changed.The same new benchmark file was run separately against unchanged
3921e54and this source tree, after warmup, taking the median of five samples per size:These are synthetic synchronous one-element results with concurrency 8, intended to isolate aggregation from I/O latency, not end-to-end application speedups. Every sample checks exact output equality outside the timing window. Reproduce with
node perf/concat-aggregation.jsafter installing dependencies; copy the same benchmark file into a base checkout to compare. The unchanged project CI also passes on this head: fork run 43399329709. It covers lint, Node 18/20/21 on Ubuntu, Node 20 on Windows, and FirefoxHeadless browser tests on both operating systems (Node 20).AI assistance
OpenAI Codex (GPT-6 family) investigated the source, implemented the change, ran tests/benchmarks and drafted this PR under the account owner's authorization. This was found during source inspection, not a claimed production incident. No independent human code review is claimed.