Skip to content

fix(ast/estree): set value for BigIntLiterals and RegExpLiterals on JS side#9044

Merged
graphite-app[bot] merged 1 commit intomainfrom
02-11-fix_ast_estree_set_value_for_bigintliteral_s_and_regexpliteral_s_on_js_side
Feb 11, 2025
Merged

fix(ast/estree): set value for BigIntLiterals and RegExpLiterals on JS side#9044
graphite-app[bot] merged 1 commit intomainfrom
02-11-fix_ast_estree_set_value_for_bigintliteral_s_and_regexpliteral_s_on_js_side

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Feb 11, 2025

Add a "reviver" function to JSON.parse in NAPI parser module, to correctly set value field of Literals for RegExps and BigInts.

Surprisingly, judging by a local run of NAPI parser benchmarks (added in #9045), this does not seem to hurt performance. In fact the benchmarks were showing a ~2% speed-up. That's clearly nonsense - just noise - but it does suggest at least that this isn't hurting performance significantly.

@github-actions github-actions bot added the C-bug Category - Bug label Feb 11, 2025
Copy link
Member Author

overlookmotel commented Feb 11, 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 February 11, 2025 13:25
@overlookmotel overlookmotel marked this pull request as draft February 11, 2025 13:25
@overlookmotel overlookmotel changed the base branch from 02-11-fix_ast_estree_fix_serializing_regexpliteral_ to graphite-base/9044 February 11, 2025 13:56
@overlookmotel overlookmotel changed the base branch from graphite-base/9044 to 02-11-fix_ast_estree_fix_serializing_regexpliteral_ February 11, 2025 13:56
@overlookmotel overlookmotel force-pushed the 02-11-fix_ast_estree_set_value_for_bigintliteral_s_and_regexpliteral_s_on_js_side branch from 4174797 to f2914a5 Compare February 11, 2025 13:56
@overlookmotel overlookmotel changed the base branch from 02-11-fix_ast_estree_fix_serializing_regexpliteral_ to 02-11-test_napi_add_napi_parser_benchmark February 11, 2025 13:57
@overlookmotel overlookmotel marked this pull request as ready for review February 11, 2025 14:02
@overlookmotel
Copy link
Member Author

@Boshen Can I just check that you don't see any downside to this?

I guess we also need to do the same for WASM, though I'd like to leave that until later - not sure if it's going to be tricky or not.

@overlookmotel overlookmotel requested a review from Boshen February 11, 2025 14:04
@overlookmotel
Copy link
Member Author

Before this PR

┌─────────┬───────────────────────────────────────────┬────────────────────┬────────────────────────┬────────────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                                 │ Latency avg (ns)   │ Latency med (ns)       │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
├─────────┼───────────────────────────────────────────┼────────────────────┼────────────────────────┼────────────────────────┼────────────────────────┼─────────┤
│ 0       │ 'parser_napi[checker.ts]'                 │ '30756500 ± 0.60%' │ '30731583 ± 487583.50' │ '33 ± 0.59%'           │ '33 ± 1'               │ 64      │
│ 1       │ 'parser_napi[cal.com.tsx]'                │ '20221012 ± 0.61%' │ '20177500 ± 324646.00' │ '49 ± 0.61%'           │ '50 ± 1'               │ 64      │
│ 2       │ 'parser_napi[RadixUIAdoptionSection.jsx]' │ '35011 ± 0.57%'    │ '34333 ± 833.00'       │ '29114 ± 0.10%'        │ '29126 ± 691'          │ 28563   │
│ 3       │ 'parser_napi[pdf.mjs]'                    │ '9622508 ± 0.96%'  │ '9452626 ± 160250.50'  │ '104 ± 0.90%'          │ '106 ± 2'              │ 104     │
│ 4       │ 'parser_napi[antd.js]'                    │ '56439960 ± 0.42%' │ '56484437 ± 495291.00' │ '18 ± 0.41%'           │ '18 ± 0'               │ 64      │
└─────────┴───────────────────────────────────────────┴────────────────────┴────────────────────────┴────────────────────────┴────────────────────────┴─────────┘

┌─────────┬───────────────────────────────────────────┬────────────────────┬────────────────────────┬────────────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                                 │ Latency avg (ns)   │ Latency med (ns)       │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
├─────────┼───────────────────────────────────────────┼────────────────────┼────────────────────────┼────────────────────────┼────────────────────────┼─────────┤
│ 0       │ 'parser_napi[checker.ts]'                 │ '31853131 ± 3.38%' │ '31106730 ± 412833.00' │ '32 ± 2.01%'           │ '32 ± 0'               │ 64      │
│ 1       │ 'parser_napi[cal.com.tsx]'                │ '20506174 ± 0.69%' │ '20418938 ± 372541.50' │ '49 ± 0.68%'           │ '49 ± 1'               │ 64      │
│ 2       │ 'parser_napi[RadixUIAdoptionSection.jsx]' │ '35227 ± 0.67%'    │ '34250 ± 834.00'       │ '29022 ± 0.11%'        │ '29197 ± 727'          │ 28388   │
│ 3       │ 'parser_napi[pdf.mjs]'                    │ '9775875 ± 0.95%'  │ '9634625 ± 216750.00'  │ '103 ± 0.87%'          │ '104 ± 2'              │ 103     │
│ 4       │ 'parser_napi[antd.js]'                    │ '57365568 ± 0.43%' │ '57301729 ± 428750.00' │ '17 ± 0.43%'           │ '17 ± 0'               │ 64      │
└─────────┴───────────────────────────────────────────┴────────────────────┴────────────────────────┴────────────────────────┴────────────────────────┴─────────┘

┌─────────┬───────────────────────────────────────────┬────────────────────┬────────────────────────┬────────────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                                 │ Latency avg (ns)   │ Latency med (ns)       │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
├─────────┼───────────────────────────────────────────┼────────────────────┼────────────────────────┼────────────────────────┼────────────────────────┼─────────┤
│ 0       │ 'parser_napi[checker.ts]'                 │ '31085293 ± 0.55%' │ '30965896 ± 351458.50' │ '32 ± 0.54%'           │ '32 ± 0'               │ 64      │
│ 1       │ 'parser_napi[cal.com.tsx]'                │ '20594562 ± 0.67%' │ '20503708 ± 387125.00' │ '49 ± 0.66%'           │ '49 ± 1'               │ 64      │
│ 2       │ 'parser_napi[RadixUIAdoptionSection.jsx]' │ '35704 ± 0.65%'    │ '34583 ± 708.00'       │ '28587 ± 0.10%'        │ '28916 ± 580'          │ 28008   │
│ 3       │ 'parser_napi[pdf.mjs]'                    │ '9781761 ± 0.76%'  │ '9693042 ± 321667.00'  │ '102 ± 0.75%'          │ '103 ± 4'              │ 103     │
│ 4       │ 'parser_napi[antd.js]'                    │ '57240627 ± 0.50%' │ '57340749 ± 541271.00' │ '17 ± 0.50%'           │ '17 ± 0'               │ 64      │
└─────────┴───────────────────────────────────────────┴────────────────────┴────────────────────────┴────────────────────────┴────────────────────────┴─────────┘

Averages:
checker.ts: 31231641
cal.com.tsx: 20440583
RadixUIAdoptionSection.jsx: 35314

After this PR

┌─────────┬───────────────────────────────────────────┬────────────────────┬────────────────────────┬────────────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                                 │ Latency avg (ns)   │ Latency med (ns)       │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
├─────────┼───────────────────────────────────────────┼────────────────────┼────────────────────────┼────────────────────────┼────────────────────────┼─────────┤
│ 0       │ 'parser_napi[checker.ts]'                 │ '29341421 ± 0.59%' │ '29197271 ± 446791.50' │ '34 ± 0.57%'           │ '34 ± 1'               │ 64      │
│ 1       │ 'parser_napi[cal.com.tsx]'                │ '19346945 ± 0.94%' │ '19273458 ± 410250.00' │ '52 ± 0.89%'           │ '52 ± 1'               │ 64      │
│ 2       │ 'parser_napi[RadixUIAdoptionSection.jsx]' │ '34664 ± 0.48%'    │ '34250 ± 750.00'       │ '29166 ± 0.08%'        │ '29197 ± 626'          │ 28849   │
│ 3       │ 'parser_napi[pdf.mjs]'                    │ '9402403 ± 0.80%'  │ '9278916 ± 116166.00'  │ '107 ± 0.73%'          │ '108 ± 1'              │ 107     │
│ 4       │ 'parser_napi[antd.js]'                    │ '55046186 ± 0.32%' │ '55006917 ± 418771.00' │ '18 ± 0.31%'           │ '18 ± 0'               │ 64      │
└─────────┴───────────────────────────────────────────┴────────────────────┴────────────────────────┴────────────────────────┴────────────────────────┴─────────┘

┌─────────┬───────────────────────────────────────────┬────────────────────┬─────────────────────────┬────────────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                                 │ Latency avg (ns)   │ Latency med (ns)        │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
├─────────┼───────────────────────────────────────────┼────────────────────┼─────────────────────────┼────────────────────────┼────────────────────────┼─────────┤
│ 0       │ 'parser_napi[checker.ts]'                 │ '30291898 ± 1.33%' │ '30287750 ± 1344791.50' │ '33 ± 1.30%'           │ '33 ± 1'               │ 64      │
│ 1       │ 'parser_napi[cal.com.tsx]'                │ '20633551 ± 0.77%' │ '20574250 ± 311479.50'  │ '49 ± 0.74%'           │ '49 ± 1'               │ 64      │
│ 2       │ 'parser_napi[RadixUIAdoptionSection.jsx]' │ '35256 ± 1.57%'    │ '34250 ± 791.00'        │ '29099 ± 0.10%'        │ '29197 ± 659'          │ 28365   │
│ 3       │ 'parser_napi[pdf.mjs]'                    │ '9677847 ± 0.88%'  │ '9541105 ± 233521.50'   │ '104 ± 0.83%'          │ '105 ± 3'              │ 104     │
│ 4       │ 'parser_napi[antd.js]'                    │ '57025924 ± 0.42%' │ '56938271 ± 439229.50'  │ '18 ± 0.41%'           │ '18 ± 0'               │ 64      │
└─────────┴───────────────────────────────────────────┴────────────────────┴─────────────────────────┴────────────────────────┴────────────────────────┴─────────┘

┌─────────┬───────────────────────────────────────────┬────────────────────┬────────────────────────┬────────────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                                 │ Latency avg (ns)   │ Latency med (ns)       │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
├─────────┼───────────────────────────────────────────┼────────────────────┼────────────────────────┼────────────────────────┼────────────────────────┼─────────┤
│ 0       │ 'parser_napi[checker.ts]'                 │ '31081100 ± 0.41%' │ '31080417 ± 387667.00' │ '32 ± 0.41%'           │ '32 ± 0'               │ 64      │
│ 1       │ 'parser_napi[cal.com.tsx]'                │ '20502240 ± 0.77%' │ '20514104 ± 368042.00' │ '49 ± 0.74%'           │ '49 ± 1'               │ 64      │
│ 2       │ 'parser_napi[RadixUIAdoptionSection.jsx]' │ '35743 ± 1.30%'    │ '34542 ± 751.00'       │ '28657 ± 0.10%'        │ '28950 ± 643'          │ 27978   │
│ 3       │ 'parser_napi[pdf.mjs]'                    │ '9756898 ± 0.91%'  │ '9580333 ± 166875.00'  │ '103 ± 0.86%'          │ '104 ± 2'              │ 103     │
│ 4       │ 'parser_napi[antd.js]'                    │ '57685036 ± 0.34%' │ '57522167 ± 480979.00' │ '17 ± 0.33%'           │ '17 ± 0'               │ 64      │
└─────────┴───────────────────────────────────────────┴────────────────────┴────────────────────────┴────────────────────────┴────────────────────────┴─────────┘

Averages:
checker.ts: 30238140 (3.3% faster)
cal.com.tsx: 20160912 (1.9% faster)
RadixUIAdoptionSection.jsx: 35221 (0.3% faster)

@overlookmotel overlookmotel changed the base branch from 02-11-test_napi_add_napi_parser_benchmark to graphite-base/9044 February 11, 2025 14:09
@overlookmotel overlookmotel force-pushed the 02-11-fix_ast_estree_set_value_for_bigintliteral_s_and_regexpliteral_s_on_js_side branch from f2914a5 to 9cc1080 Compare February 11, 2025 14:15
@overlookmotel overlookmotel changed the base branch from graphite-base/9044 to main February 11, 2025 14:16
@overlookmotel overlookmotel force-pushed the 02-11-fix_ast_estree_set_value_for_bigintliteral_s_and_regexpliteral_s_on_js_side branch from 9cc1080 to 7a0d537 Compare February 11, 2025 14:16
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Feb 11, 2025
Copy link
Member

Boshen commented Feb 11, 2025

Merge activity

  • Feb 11, 9:48 AM EST: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Feb 11, 9:48 AM EST: A user added this pull request to the Graphite merge queue.
  • Feb 11, 9:53 AM EST: A user merged this pull request with the Graphite merge queue.

…s on JS side (#9044)

Add a "reviver" function to `JSON.parse` in NAPI parser module, to correctly set `value` field of `Literal`s for `RegExp`s and `BigInt`s.

Surprisingly, judging by a local run of NAPI parser benchmarks (added in #9045), this does not seem to hurt performance. In fact the benchmarks were showing a ~2% speed-up. That's clearly nonsense - just noise - but it does suggest at least that this isn't hurting performance significantly.
@graphite-app graphite-app bot force-pushed the 02-11-fix_ast_estree_set_value_for_bigintliteral_s_and_regexpliteral_s_on_js_side branch from 7a0d537 to 41dba62 Compare February 11, 2025 14:48
@graphite-app graphite-app bot merged commit 41dba62 into main Feb 11, 2025
15 checks passed
@graphite-app graphite-app bot deleted the 02-11-fix_ast_estree_set_value_for_bigintliteral_s_and_regexpliteral_s_on_js_side branch February 11, 2025 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0-merge Merge with Graphite Merge Queue C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants