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

core: js errors as unions vs tuples to reduce allocs #9947

Merged
merged 5 commits into from
Apr 1, 2021

Conversation

AaronO
Copy link
Contributor

@AaronO AaronO commented Mar 31, 2021

This is an op-layer optimization follow-up to #9843.

It shaves off ~350ns/op of baseline overhead, making them over 2x faster by reducing allocs.

Instead of returning JS results as tuples of (Option<T>, Option<Err>) it returns them as a conceptual union type, avoiding allocating the wrapping array. We then use a "special" key name to recognize errors.

So far I've picked the error-key to be $err_class_name, but this can be easily changed or adjusted.

Results

Op-baseline benches:

Before:
test bench_op_nop     ... bench:     321,740 ns/iter (+/- 39,892)
test bench_op_pi_bin  ... bench:     786,395 ns/iter (+/- 23,765)
test bench_op_pi_json ... bench:     681,285 ns/iter (+/- 26,579)

After:
test bench_op_nop     ... bench:     318,910 ns/iter (+/- 16,233)
test bench_op_pi_bin  ... bench:     402,301 ns/iter (+/- 28,707)
test bench_op_pi_json ... bench:     294,627 ns/iter (+/- 14,079)

@AaronO AaronO changed the title core: return errors as unions vs tuples to reduce allocs core/ops: js errors as unions vs tuples to reduce allocs Mar 31, 2021
@AaronO AaronO changed the title core/ops: js errors as unions vs tuples to reduce allocs core: js errors as unions vs tuples to reduce allocs Mar 31, 2021
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

LGTM - thanks Aaron

@ry ry merged commit 6eace4d into denoland:main Apr 1, 2021
@AaronO AaronO deleted the core/ops-union-errors branch April 1, 2021 11:31
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

2 participants