-
-
Notifications
You must be signed in to change notification settings - Fork 726
perf(napi/parser, napi/oxlint): lazy visit: faster check for exit visitor #12496
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(napi/parser, napi/oxlint): lazy visit: faster check for exit visitor #12496
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { Bench } from 'tinybench';
const bench = new Bench({ name: 'simple benchmark', time: 100 });
const data = [];
for (let i = 0; i < 1000; i++) {
data.push(Math.random() > 0.5 ? () => {} : null);
}
bench
.add('coerce boolean', () => {
for (const item of data) {
if (item) {
item();
}
}
})
.add('vs null', async () => {
for (const item of data) {
if (item !== null) {
item();
}
}
});
await bench.run();
console.log(bench.name);
console.table(bench.table());
┌─────────┬──────────────────┬──────────────────┬──────────────────┬────────────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
├─────────┼──────────────────┼──────────────────┼──────────────────┼────────────────────────┼────────────────────────┼─────────┤
│ 0 │ 'coerce boolean' │ '2326.9 ± 0.21%' │ '2292.0 ± 1.00' │ '431865 ± 0.03%' │ '436300 ± 190' │ 42977 │
│ 1 │ 'vs null' │ '1756.3 ± 0.37%' │ '1750.0 ± 0.00' │ '572547 ± 0.03%' │ '571429 ± 0' │ 56937 │
└─────────┴──────────────────┴──────────────────┴──────────────────┴────────────────────────┴────────────────────────┴─────────┘
‘vs null’ is faster than ‘coerce boolean’ by
- ~24.5% in latency
- ~32.6% in throughput
Merge activity
|
…itor (#12496) In the absence of benchmarks, I don't know for sure that this is a perf improvement. But I assume so. `if (exit)` requires coercion of `exit` to a boolean, whereas `if (exit !== null)` is a simpler check - comparison to a single known constant. Once we have reliable benchmarking set up for raw transfer, we can revisit and tweak the code in many ways, but I think in the meantime this change is *probably* an improvement.
f9a0241 to
69f8b63
Compare

In the absence of benchmarks, I don't know for sure that this is a perf improvement. But I assume so.
if (exit)requires coercion ofexitto a boolean, whereasif (exit !== null)is a simpler check - comparison to a single known constant.Once we have reliable benchmarking set up for raw transfer, we can revisit and tweak the code in many ways, but I think in the meantime this change is probably an improvement.