Skip to content

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Oct 11, 2025

Summary

Reorders Statement and Expression match arms in oxc_codegen to align with parser frequency, improving branch prediction performance.

Changes

Statement match reordering:

  • Most common first: BlockStatement, ExpressionStatement, VariableDeclaration, IfStatement, ReturnStatement, FunctionDeclaration
  • Control flow: ForStatement, WhileStatement, DoWhileStatement, SwitchStatement, etc.
  • Less common: WithStatement, DebuggerStatement
  • TypeScript-specific moved to bottom

Expression match reordering:

  • Most common first: Identifier, StaticMemberExpression, ComputedMemberExpression, CallExpression
  • Literals: NumericLiteral, StringLiteral, BooleanLiteral, NullLiteral
  • Binary/logical operations and object/array literals
  • JSX and TypeScript assertions moved to bottom

The new order follows the parser's pattern matching sequence (from parse_statement_list_item and parse_primary_expression), which reflects real-world JavaScript/TypeScript code frequency.

Test plan

  • All oxc_codegen tests pass (86 passed)
  • Integration with oxc_transformer verified (30 tests passed)
  • Release build compiles successfully
  • Code formatted with just fmt

🤖 Generated with Claude Code

Reorder Statement and Expression match arms to align with parser
frequency, improving branch prediction performance.

Changes:
- Statement: BlockStatement, ExpressionStatement, VariableDeclaration
  and control flow statements moved to top, TS-specific moved to bottom
- Expression: Identifier, member access, calls, and literals moved to
  top, JSX and TS assertions moved to bottom

The new order follows the parser's pattern matching sequence, which
reflects real-world JavaScript/TypeScript code frequency.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings October 11, 2025 03:17
@graphite-app
Copy link
Contributor

graphite-app bot commented Oct 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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR reorders match arms in the Statement and Expression enums within the code generator to align with typical JavaScript/TypeScript usage patterns, potentially improving branch prediction performance through better CPU cache utilization.

Key changes:

  • Reordered Statement match arms to prioritize common statements like BlockStatement, ExpressionStatement, and VariableDeclaration
  • Reordered Expression match arms to prioritize frequent expressions like Identifier, member access, and function calls
  • Moved TypeScript-specific constructs to the bottom as they're less common in runtime scenarios

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@github-actions github-actions bot added A-codegen Area - Code Generation C-performance Category - Solution not expected to change functional behavior, only performance labels Oct 11, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 11, 2025

CodSpeed Performance Report

Merging #14496 will not alter performance

Comparing perf/codegen-reorder-match-arms (7387377) with main (d0a8e3e)1

Summary

✅ 37 untouched

Footnotes

  1. No successful run was found on main (a631dd7) during the generation of this report, so d0a8e3e was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@Boshen Boshen merged commit ea3f362 into main Oct 11, 2025
28 checks passed
@Boshen Boshen deleted the perf/codegen-reorder-match-arms branch October 11, 2025 03:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-codegen Area - Code Generation 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.

2 participants