Skip to content

perf(napi/parser): faster fixup of BigInts and RegExps#10820

Merged
graphite-app[bot] merged 1 commit intomainfrom
05-05-perf_napi_parser_faster_fixup_of_bigint_s_and_regexp_s
May 6, 2025
Merged

perf(napi/parser): faster fixup of BigInts and RegExps#10820
graphite-app[bot] merged 1 commit intomainfrom
05-05-perf_napi_parser_faster_fixup_of_bigint_s_and_regexp_s

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented May 5, 2025

#10791 fixed the performance of oxc-parser NPM package by removing the reviver from JSON.parse call. However, it replaced it with a complete traversal of the AST on JS side to locate Literal nodes and update them.

Instead, generate a list of paths to Literal nodes needing fixing on Rust side in ESTree serializer.

e.g. for this program:

123n;
foo(/xyz/);

the fix paths are:

[
    ["body", 0, "expression"],
    ["body", 1, "expression", "arguments", 2]
]

Having the location of nodes which need updating reduces work on JS side, as no need to search the entire AST.

Running pnpm run bench (in napi/parser) locally shows between 8% and 15% speed-up from this change.

@github-actions github-actions bot added the A-ast Area - AST label May 5, 2025
@github-actions github-actions bot added the C-performance Category - Solution not expected to change functional behavior, only performance label May 5, 2025
Copy link
Member Author

overlookmotel commented May 5, 2025


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 May 5, 2025 17:23
@codspeed-hq
Copy link

codspeed-hq bot commented May 5, 2025

CodSpeed Instrumentation Performance Report

Merging #10820 will degrade performances by 4.89%

Comparing 05-05-perf_napi_parser_faster_fixup_of_bigint_s_and_regexp_s (49a6f97) with main (24fcb1e)

Summary

❌ 1 regressions
✅ 35 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
estree[checker.ts] 96.8 ms 101.7 ms -4.89%

@overlookmotel
Copy link
Member Author

Regression in estree benchmark is expected. We're doing more work on Rust side in order to save work on JS side. That benchmark only measures the Rust side.

@overlookmotel overlookmotel requested a review from Boshen May 5, 2025 17:32
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label May 6, 2025
Copy link
Member

Boshen commented May 6, 2025

Merge activity

#10791 fixed the performance of `oxc-parser` NPM package by removing the reviver from `JSON.parse` call. However, it replaced it with a complete traversal of the AST on JS side to locate `Literal` nodes and update them.

Instead, generate a list of paths to `Literal` nodes needing fixing on Rust side in `ESTree` serializer.

e.g. for this program:

```js
123n;
foo(/xyz/);
```

the fix paths are:

```json
[
    ["body", 0, "expression"],
    ["body", 1, "expression", "arguments", 2]
]
```

Having the location of nodes which need updating reduces work on JS side, as no need to search the entire AST.

Running `pnpm run bench` (in `napi/parser`) locally shows between 8% and 15% speed-up from this change.
@graphite-app graphite-app bot force-pushed the 05-05-ci_benchmarks_estree_benchmark_use_black_box_on_result_of_to_estree_ts_json_ branch from 2362045 to 33969ac Compare May 6, 2025 02:35
@graphite-app graphite-app bot force-pushed the 05-05-perf_napi_parser_faster_fixup_of_bigint_s_and_regexp_s branch from 514f81f to 49a6f97 Compare May 6, 2025 02:35
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label May 6, 2025
Base automatically changed from 05-05-ci_benchmarks_estree_benchmark_use_black_box_on_result_of_to_estree_ts_json_ to main May 6, 2025 02:41
@graphite-app graphite-app bot merged commit 49a6f97 into main May 6, 2025
29 checks passed
@graphite-app graphite-app bot deleted the 05-05-perf_napi_parser_faster_fixup_of_bigint_s_and_regexp_s branch May 6, 2025 02:42
graphite-app bot pushed a commit that referenced this pull request May 7, 2025
…on separate lines (#10869)

#10820 changed how `BigInt`s and `RegExp`s are fixed in ESTree AST on JS side. It adds a list of fix paths to the end of the JSON.

Add line breaks after the inserted header, and before the inserted footer. This will allow playground to easily trim off the header and footer and display the raw JSON instead of converting the AST Object back to JSON with `JSON.stringify`. oxc-project/playground#101
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast Area - AST 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.

4 participants