Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(ext/streams): optimize streams #20649

Merged
merged 25 commits into from
Oct 13, 2023
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into perf-web-streams
Signed-off-by: Luca Casonato <[email protected]>
  • Loading branch information
lucacasonato authored Oct 11, 2023
commit 271d1124431cfde44e9613ea0680201f4b3f4a7f
26 changes: 22 additions & 4 deletions ext/web/06_streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,7 @@ function initializeTransformStream(
}

function cancelAlgorithm(reason) {
transformStreamErrorWritableAndUnblockWrite(stream, reason);
return PromiseResolve(undefined);
return transformStreamDefaultSourceCancelAlgorithm(stream, reason);
}

stream[_readable] = createReadableStream(
Expand Down Expand Up @@ -3757,6 +3756,7 @@ function setUpTransformStreamDefaultControllerFromTransformer(
};
/** @type {(controller: TransformStreamDefaultController<O>) => Promise<void>} */
let flushAlgorithm = _defaultFlushAlgorithm;
let cancelAlgorithm = _defaultCancelAlgorithm;
if (transformerDict.transform !== undefined) {
transformAlgorithm = (chunk, controller) =>
webidl.invokeCallbackFunction(
Expand Down Expand Up @@ -4054,8 +4054,26 @@ function transformStreamDefaultControllerTerminate(controller) {
* @returns {Promise<void>}
*/
function transformStreamDefaultSinkAbortAlgorithm(stream, reason) {
transformStreamError(stream, reason);
return PromiseResolve(undefined);
const controller = stream[_controller];
if (controller[_finishPromise] !== undefined) {
return controller[_finishPromise].promise;
}
const readable = stream[_readable];
controller[_finishPromise] = new Deferred();
const cancelPromise = controller[_cancelAlgorithm](reason);
transformStreamDefaultControllerClearAlgorithms(controller);
transformPromiseWith(cancelPromise, () => {
if (readable[_state] === "errored") {
controller[_finishPromise].reject(readable[_storedError]);
} else {
readableStreamDefaultControllerError(readable[_controller], reason);
controller[_finishPromise].resolve(undefined);
}
}, (r) => {
readableStreamDefaultControllerError(readable[_controller], r);
controller[_finishPromise].reject(r);
});
return controller[_finishPromise].promise;
}

/**
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.