perf(ext/web): reduce promise allocations in streams#32652
Merged
bartlomieju merged 1 commit intodenoland:mainfrom Mar 12, 2026
Merged
perf(ext/web): reduce promise allocations in streams#32652bartlomieju merged 1 commit intodenoland:mainfrom
bartlomieju merged 1 commit intodenoland:mainfrom
Conversation
Reduces the number of promise allocations in the web streams implementation by: 1. Collapsing `uponPromise`'s double `.then()` chain into a single `.then()` — the second chain was only for catching internal assertion errors, which can be handled via try/catch in the wrapped handlers instead. 2. Converting `setPromiseIsHandledToTrue(PromisePrototypeThen(...))` patterns to use the optimized `uponPromise` directly, saving one promise allocation per call site. 3. Merging separate `uponFulfillment` + `uponRejection` calls on the same promise (in `readableStreamDefaultControllerCallPullIfNeeded`) into a single `uponPromise` call, halving the promise allocations. Ref: denoland#22915 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
nathanwhit
approved these changes
Mar 12, 2026
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.
Summary
uponPromise's double.then()chain into a single.then()— the second chain only caught internal assertion errors, now handled via try/catch in wrapped handlerssetPromiseIsHandledToTrue(PromisePrototypeThen(...))patterns to useuponPromisedirectly (2 call sites)uponFulfillment+uponRejectionon the same promise into a singleuponPromiseinreadableStreamDefaultControllerCallPullIfNeededEach
uponPromisecall previously created 2 promises (double.then()); now creates 1. Combined with the other changes, this reduces promise allocations across all 37 call sites in the streams implementation.Closes #22915
Benchmark
Results (debug build, avg of 3 runs)
Test plan
cargo test unit::streamspassesdeno lint ext/web/06_streams.jspasses🤖 Generated with Claude Code