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(runtime): optimize PermissionState::check #9993

Merged
merged 1 commit into from
Apr 12, 2021

Conversation

AaronO
Copy link
Contributor

@AaronO AaronO commented Apr 4, 2021

By converting log_perm_access() to a macro, so the message sub-expression is dropped at compile time in release mode. Otherwise it made allocations and added substantial overhead to opcalls.

Benches

Measured on perf_now (op_now) from deno_common:

Before:
perf_now:                n = 5000000, dt = 2.429s, r = 2058460/s, t = 485ns/op

After:
perf_now:                n = 5000000, dt = 1.773s, r = 2820079/s, t = 354ns/op

Flamegraph views

Before:

image

After

image

@AaronO AaronO changed the title runtime: optimize PermissionState::check perf(runtime): optimize PermissionState::check Apr 4, 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.

Cool - seems simple enough.

Out of curiosity wouldn't #[inline] also do the trick?

@AaronO AaronO closed this Apr 12, 2021
@AaronO AaronO force-pushed the perf/permissionstate-check branch from 6840ae0 to 875ac73 Compare April 12, 2021 09:49
Avoid allocs for log_perm_access() for non-debug builds
@AaronO AaronO reopened this Apr 12, 2021
@AaronO
Copy link
Contributor Author

AaronO commented Apr 12, 2021

Cool - seems simple enough.

Out of curiosity wouldn't #[inline] also do the trick?

I've refactored this so it no longer uses a macro, it instead inlines it and calls Self::fmt_access inside debug!(), which will cause a double alloc of the access msg in the prompt path, but only when debug logging is enabled which is fine IMO (since debug logging + prompt isn't a hotpath).

@AaronO
Copy link
Contributor Author

AaronO commented Apr 12, 2021

Both the flamegraph and the deno_common bench confirm this optimization:

Before (main):
perf_now:            	n = 500000, dt = 0.155s, r = 3225806/s, t = 310ns/op

After (this PR):
perf_now:            	n = 500000, dt = 0.094s, r = 5319149/s, t = 188ns/op

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

@bartlomieju bartlomieju merged commit 5c2a8cd into denoland:main Apr 12, 2021
@AaronO AaronO deleted the perf/permissionstate-check branch April 12, 2021 11:24
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

3 participants