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/websocket): use opAsync2 to avoid spread deopt #18525

Merged
merged 2 commits into from
Mar 31, 2023

Conversation

littledivy
Copy link
Member

This commit adds a new core API opAsync2 to call an async op with atmost 2 arguments. Spread argument iterators has a pretty big perf hit when calling ops.

name avg msg/sec/core
1.32.1 127820.750000
#18506 140079.000000
#18506 + #18509 150104.250000
#18506 + #18509 + this 157340.000000

@littledivy littledivy enabled auto-merge (squash) March 31, 2023 13:05
Copy link
Collaborator

@aapoalas aapoalas left a comment

Choose a reason for hiding this comment

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

Looks good to me. One thing I wonder is what was the performance impact of doing async ops with a callback API? Ie. Create a CB taking the promiseid parameter that core then synchronously calls to init the actual op.

@petamoriken
Copy link
Contributor

Maybe switch (args.length) {} is good for performance in opAsync.

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

Please migrate all relevant ops to this variant

@littledivy
Copy link
Member Author

@aapoalas For promises, we currently batch multiple completed operations in one single opresolve call. With callbacks for each one, it will be multiple entries into JS. I think we did investigate this some time ago.

@aapoalas
Copy link
Collaborator

@aapoalas For promises, we currently batch multiple completed operations in one single opresolve call. With callbacks for each one, it will be multiple entries into JS. I think we did investigate this some time ago.

No I mean for starting the op: What the opAsync call essentially does is that it injects the promiseid argument to the actual call's arguments. If instead it took as parameter a single callback that it called with the promiseid then the caller of opAsync could in that callback call the actual op binding function without spreading args.

@littledivy
Copy link
Member Author

No I mean for starting the op: What the opAsync call essentially does is that it injects the promiseid argument to the actual call's arguments. If instead it took as parameter a single callback that it called with the promiseid then the caller of opAsync could in that callback call the actual op binding function without spreading args.

Yup that would work. We could also try arguments.length if thats faster. For now, I like opAsync2, opAsync3 because its easier to mass replace.

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

LGTM

@littledivy littledivy merged commit aa9b94a into denoland:main Mar 31, 2023
mmastrac pushed a commit that referenced this pull request Mar 31, 2023
This commit adds a new core API `opAsync2` to call an async op with
atmost 2 arguments. Spread argument iterators has a pretty big perf hit
when calling ops.

| name | avg msg/sec/core |
| --- | --- |
| 1.32.1 | `127820.750000` |
| #18506 | `140079.000000` |
| #18506 + #18509 | `150104.250000` |
| #18506 + #18509 + this | `157340.000000` |
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.

None yet

4 participants