Skip to content

Conversation

@cawalch
Copy link
Collaborator

@cawalch cawalch commented Jul 13, 2025

  • Replace object spread to improve performance of lexer
  • Direct assignment + push is better optimized by V8's JIT compiler

Before

┌─────────┬─────────────────────────────────┬──────────────┬────────────────────┬──────────┬──────────┐
│ (index) │ Task Name                       │ ops/sec      │ Average Time (ns)  │ Margin   │ Samples  │
├─────────┼─────────────────────────────────┼──────────────┼────────────────────┼──────────┼──────────┤
│ 0       │ 'Parser#single_expr'            │ '14,147,126' │ 70.68573011330783  │ '±0.70%' │ 14147127 │
│ 1       │ 'Parser#single_subexpr'         │ '6,499,427'  │ 153.85971442402027 │ '±0.58%' │ 6499428  │
│ 2       │ 'Parser#deeply_nested_50'       │ '323,190'    │ 3094.1537388112297 │ '±0.61%' │ 323191   │
│ 3       │ 'Parser#deeply_nested_50_index' │ '185,184'    │ 5400.025428624975  │ '±0.55%' │ 185185   │
│ 4       │ 'Parser#basic_list_projection'  │ '3,725,417'  │ 268.4262576707434  │ '±0.70%' │ 3725418  │
│ 5       │ 'Lexer#common_identifiers'      │ '1,628,946'  │ 613.8937718658917  │ '±0.46%' │ 1628947  │
│ 6       │ 'Lexer#mixed_tokens'            │ '1,639,320'  │ 610.008940897486   │ '±0.58%' │ 1639321  │
│ 7       │ 'Lexer#function_calls'          │ '2,283,372'  │ 437.948678117997   │ '±0.70%' │ 2283373  │
└─────────┴─────────────────────────────────┴──────────────┴────────────────────┴──────────┴──────────┘

After

┌─────────┬─────────────────────────────────┬──────────────┬────────────────────┬──────────┬──────────┐
│ (index) │ Task Name                       │ ops/sec      │ Average Time (ns)  │ Margin   │ Samples  │
├─────────┼─────────────────────────────────┼──────────────┼────────────────────┼──────────┼──────────┤
│ 0       │ 'Parser#single_expr'            │ '16,053,435' │ 62.29196192015425  │ '±0.45%' │ 16053436 │
│ 1       │ 'Parser#single_subexpr'         │ '7,385,154'  │ 135.40677954624348 │ '±0.49%' │ 7385155  │
│ 2       │ 'Parser#deeply_nested_50'       │ '322,845'    │ 3097.4563878751533 │ '±0.63%' │ 322846   │
│ 3       │ 'Parser#deeply_nested_50_index' │ '190,063'    │ 5261.401470032018  │ '±0.61%' │ 190064   │
│ 4       │ 'Parser#basic_list_projection'  │ '4,488,960'  │ 222.76873289856564 │ '±0.04%' │ 4488961  │
│ 5       │ 'Lexer#common_identifiers'      │ '1,764,451'  │ 566.748222111554   │ '±0.08%' │ 1764452  │
│ 6       │ 'Lexer#mixed_tokens'            │ '1,723,512'  │ 580.2105043600956  │ '±0.61%' │ 1723513  │
│ 7       │ 'Lexer#function_calls'          │ '2,560,641'  │ 390.5271908375201  │ '±0.29%' │ 2560642  │
└─────────┴─────────────────────────────────┴──────────────┴────────────────────┴──────────┴──────────┘

 - Replace object spread to improve performance of lexer
 - Direct assignment + push is better optimized by V8's JIT compiler

Before

```
┌─────────┬─────────────────────────────────┬──────────────┬────────────────────┬──────────┬──────────┐
│ (index) │ Task Name                       │ ops/sec      │ Average Time (ns)  │ Margin   │ Samples  │
├─────────┼─────────────────────────────────┼──────────────┼────────────────────┼──────────┼──────────┤
│ 0       │ 'Parser#single_expr'            │ '14,147,126' │ 70.68573011330783  │ '±0.70%' │ 14147127 │
│ 1       │ 'Parser#single_subexpr'         │ '6,499,427'  │ 153.85971442402027 │ '±0.58%' │ 6499428  │
│ 2       │ 'Parser#deeply_nested_50'       │ '323,190'    │ 3094.1537388112297 │ '±0.61%' │ 323191   │
│ 3       │ 'Parser#deeply_nested_50_index' │ '185,184'    │ 5400.025428624975  │ '±0.55%' │ 185185   │
│ 4       │ 'Parser#basic_list_projection'  │ '3,725,417'  │ 268.4262576707434  │ '±0.70%' │ 3725418  │
│ 5       │ 'Lexer#common_identifiers'      │ '1,628,946'  │ 613.8937718658917  │ '±0.46%' │ 1628947  │
│ 6       │ 'Lexer#mixed_tokens'            │ '1,639,320'  │ 610.008940897486   │ '±0.58%' │ 1639321  │
│ 7       │ 'Lexer#function_calls'          │ '2,283,372'  │ 437.948678117997   │ '±0.70%' │ 2283373  │
└─────────┴─────────────────────────────────┴──────────────┴────────────────────┴──────────┴──────────┘
```

After

```
┌─────────┬─────────────────────────────────┬──────────────┬────────────────────┬──────────┬──────────┐
│ (index) │ Task Name                       │ ops/sec      │ Average Time (ns)  │ Margin   │ Samples  │
├─────────┼─────────────────────────────────┼──────────────┼────────────────────┼──────────┼──────────┤
│ 0       │ 'Parser#single_expr'            │ '16,053,435' │ 62.29196192015425  │ '±0.45%' │ 16053436 │
│ 1       │ 'Parser#single_subexpr'         │ '7,385,154'  │ 135.40677954624348 │ '±0.49%' │ 7385155  │
│ 2       │ 'Parser#deeply_nested_50'       │ '322,845'    │ 3097.4563878751533 │ '±0.63%' │ 322846   │
│ 3       │ 'Parser#deeply_nested_50_index' │ '190,063'    │ 5261.401470032018  │ '±0.61%' │ 190064   │
│ 4       │ 'Parser#basic_list_projection'  │ '4,488,960'  │ 222.76873289856564 │ '±0.04%' │ 4488961  │
│ 5       │ 'Lexer#common_identifiers'      │ '1,764,451'  │ 566.748222111554   │ '±0.08%' │ 1764452  │
│ 6       │ 'Lexer#mixed_tokens'            │ '1,723,512'  │ 580.2105043600956  │ '±0.61%' │ 1723513  │
│ 7       │ 'Lexer#function_calls'          │ '2,560,641'  │ 390.5271908375201  │ '±0.29%' │ 2560642  │
└─────────┴─────────────────────────────────┴──────────────┴────────────────────┴──────────┴──────────┘
```

<!-- ps-id: 907c6ded-95d1-43aa-becd-a56c74c7b6f6 -->
@cawalch cawalch merged commit 251133b into main Jul 13, 2025
7 checks passed
@cawalch cawalch deleted the perf-lexer-use-direct-push branch July 16, 2025 20:27
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.

2 participants