Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Jul 24, 2025

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.

@github-actions github-actions bot added A-ast-tools Area - AST tools C-performance Category - Solution not expected to change functional behavior, only performance labels Jul 24, 2025
Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@overlookmotel overlookmotel marked this pull request as ready for review July 24, 2025 10:19
@overlookmotel overlookmotel requested a review from camc314 July 24, 2025 10:19
Copy link
Contributor

@camc314 camc314 left a 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

@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Jul 24, 2025
Copy link
Contributor

camc314 commented Jul 24, 2025

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.
@graphite-app graphite-app bot force-pushed the 07-23-perf_napi_parser_napi_oxlint_lazy_visit_faster_check_for_exit_visitor branch from f9a0241 to 69f8b63 Compare July 24, 2025 10:27
@graphite-app graphite-app bot merged commit 69f8b63 into main Jul 24, 2025
15 checks passed
@graphite-app graphite-app bot deleted the 07-23-perf_napi_parser_napi_oxlint_lazy_visit_faster_check_for_exit_visitor branch July 24, 2025 10:34
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast-tools Area - AST tools C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants