Skip to content

Rework promise rejection tracker #1058

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

Merged
merged 1 commit into from
May 20, 2025
Merged

Conversation

saghul
Copy link
Contributor

@saghul saghul commented May 19, 2025

This reverts a75498b and a4a5a17 (except the tests) and adapts bellard/quickjs@3c39307 which also passes the tests and feels like a better solution overall.

Ref: #1038

@saghul saghul requested a review from bnoordhuis May 19, 2025 07:33
@saghul
Copy link
Contributor Author

saghul commented May 19, 2025

Sorry for the back and forth here, I got blinsided.

Copy link
Contributor

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rejected_promise_list is scanned in linear fashion. How big is it expected to grow under normal operations?

I understand in-flight promises are added and removed continuously so I suppose it can grow pretty big in a promise-heavy script?

@@ -51060,7 +51016,8 @@ static __exception int perform_promise_then(JSContext *ctx,
if (s->promise_state == JS_PROMISE_REJECTED && !s->is_handled) {
JSRuntime *rt = ctx->rt;
if (rt->host_promise_rejection_tracker)
JS_EnqueueJob(ctx, promise_rejection_tracker_job, 1, &promise);
rt->host_promise_rejection_tracker(ctx, promise, s->promise_result,
true, rt->host_promise_rejection_tracker_opaque);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is is_handled==true? I would've expected false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because here we are attaching a catch AFAIK.

@saghul
Copy link
Contributor Author

saghul commented May 19, 2025

rejected_promise_list is scanned in linear fashion. How big is it expected to grow under normal operations?

Not sure, I guess I can measure? Any specific test you'd like to run?

I understand in-flight promises are added and removed continuously so I suppose it can grow pretty big in a promise-heavy script?

Maybe? Any particular worries?

This reverts a75498b and
a4a5a17 (except the tests) and adapts
bellard/quickjs@3c39307
which also passes the tests and feels like a better solution overall.

Ref: #1038
@saghul saghul force-pushed the rework-promise-rejection-tracker branch from fb80890 to 6fddfe8 Compare May 19, 2025 09:16
@bnoordhuis
Copy link
Contributor

I don't think we have tests or benchmarks (neither does web-tooling-benchmark) that really stress-tests promises. I'm thinking of a modern node.js server app, they commonly have 100s or 1,000s of promises in-flight at any given moment.

@saghul
Copy link
Contributor Author

saghul commented May 19, 2025

Right. Note that we only really keep track of rejected ones so the rest of the lookups should be fast? Unless you have a ton of rejected ones...

Are you ok landing as is and looking into perf improvements if / when necessary?

@bnoordhuis
Copy link
Contributor

Yeah, that's fine. Just something to be mindful of.

@saghul saghul merged commit f316b3d into master May 20, 2025
127 checks passed
@saghul saghul deleted the rework-promise-rejection-tracker branch May 20, 2025 08:54
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.

2 participants