Skip to content

perf: avoid per-element allocations in Result.combine - #691

Open
hood wants to merge 1 commit into
supermacro:masterfrom
hood:perf/combine-loop
Open

hood wants to merge 1 commit into
supermacro:masterfrom
hood:perf/combine-loop

Conversation

@hood

@hood hood commented Nov 5, 2026

Copy link
Copy Markdown

Summary

Rewrites combineResultList as a plain loop into a pre-sized array. No more per-element closure and Ok allocation from acc.map(list => list.push(...)). Short-circuit on the first Err is unchanged.

Closes #690

Results

Node 26, median of 5 runs, esbuild CJS bundle of src/.

Benchmark Before After Gain
Result.combine of 10k Ok 33.1µs 16.1µs 2.1x

Also benefits ResultAsync.combine, which uses the same helper. All 117 tests, tsc, test types and lint pass.

@changeset-bot

changeset-bot Bot commented Nov 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 593c4a8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
neverthrow Patch

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 branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Result.combine allocates a closure and an Ok per element

1 participant