Skip to content

Conversation

Copy link

Copilot AI commented Nov 24, 2025

Description

Converts the oxc parser implementation from asynchronous parse to synchronous parseSync, improving parsing performance for JavaScript and TypeScript files.

Changes Made

  1. Updated src/language-js/parse/oxc.js:

    • Changed import from parse to parseSync from oxc-parser
    • Converted parseWithOptions, parseJs, and parseTs from async to sync functions
    • Replaced tryCombinations with tryCombinationsSync
  2. Updated scripts/build/build-oxc-wasm-parser.js:

    • Changed browser bundle export from {parseSync as parse} to {parseSync} for consistency

Performance Improvements

Comprehensive benchmark results for oxc-ts parser on **/*.{js,ts} files using --experimental-cli --no-cache flags:

Async version (using parse):

  • index.mjs: 8.236s real, 27.169s user, 2.051s sys
  • index.browser.mjs: 8.513s real, 29.168s user, 1.520s sys

Sync version (using parseSync):

  • index.mjs: 7.978s real, 26.922s user, 1.733s sys (~3.1% faster, 15.5% less system time)
  • index.browser.mjs: 8.435s real, 28.783s user, 1.532s sys (~0.9% faster, 1.3% less CPU time)

The synchronous version shows consistent performance improvements across both builds. The Node.js build demonstrates the most significant gains with 258ms faster real time and a 15.5% reduction in system time. Testing with the experimental CLI and no cache provides a clearer view of actual parser performance.

Checklist

  • I've added tests to confirm my change works.
  • (If changing the API or CLI) I've documented the changes I've made (in the docs/ directory).
  • (If the change is user-facing) I've added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I've read the contributing guidelines.
Original prompt

Please help me to get some numbers.

First run yarn build to build

Compare for oxc parser with this command

time (node dist/prettier/bin/prettier.cjs debug "**/*.js" --parser=oxc --plugin=./dist/plugin-oxc/index.mjs -c --with-node-modules --log-level=silent > /dev/null)
time (node dist/prettier/bin/prettier.cjs debug "**/*.js" --parser=oxc --plugin=./dist/plugin-oxc/index.browser.mjs -c --with-node-modules --log-level=silent > /dev/null)

Compare for oxc-ts parser with this command

time (node dist/prettier/bin/prettier.cjs debug "**/*.ts" --parser=oxc-ts --plugin=./dist/plugin-oxc/index.mjs -c --with-node-modules --log-level=silent > /dev/null)
time (node dist/prettier/bin/prettier.cjs debug "**/*.ts" --parser=oxc-ts --plugin=./dist/plugin-oxc/index.browser.mjs -c --with-node-modules --log-level=silent > /dev/null)

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@fisker
Copy link
Owner

fisker commented Nov 24, 2025

@copilot Can you run this too?

time (node dist/prettier/bin/prettier.cjs debug "**/*.{js,ts}" --parser=oxc-ts --plugin=./dist/plugin-oxc/index.mjs -c --with-node-modules --log-level=silent > /dev/null)
time (node dist/prettier/bin/prettier.cjs debug "**/*.{js,ts}" --parser=oxc-ts --plugin=./dist/plugin-oxc/index.browser.mjs -c --with-node-modules --log-level=silent > /dev/null)

Copilot AI changed the title [WIP] Compare performance of oxc and oxc-ts parsers Performance benchmark: oxc parser plugin comparison (Node.js vs Browser builds) Nov 24, 2025
Copilot AI requested a review from fisker November 24, 2025 18:34
Copy link
Author

Copilot AI commented Nov 24, 2025

@copilot Can you run this too?

...

Done! Benchmark results for oxc-ts parser on combined .js and .ts files:

With index.mjs: 9.495s real, 13.432s user
With index.browser.mjs: 9.352s real, 13.954s user

The browser build is slightly faster in wall-clock time (9.352s vs 9.495s) but uses more CPU time (13.954s vs 13.432s user).

@fisker
Copy link
Owner

fisker commented Nov 24, 2025

@copilot

  1. Update src/language-js/parse/oxc.js file to use parseSync instead of parse from oxc-parser and rewrite async functions in this file to sync version, tryCombinations can be replaced with tryCombinationsSync.
  2. Run the command again.

Co-authored-by: fisker <172584+fisker@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 24, 2025

@copilot

  1. Update src/language-js/parse/oxc.js file to use parseSync instead of parse from oxc-parser and rewrite async functions in this file to sync version, tryCombinations can be re...

Done! Updated oxc parser to use parseSync and converted all async functions to sync versions (commit a4162c9).

Performance results after changes:

index.mjs: 9.137s real, 12.803s user (3.8% faster than async version)
index.browser.mjs: 9.301s real, 13.682s user (0.5% faster than async version)

The synchronous version shows consistent performance improvements, especially for the Node.js build which saves ~630ms and ~4.7% CPU time.

Copilot AI changed the title Performance benchmark: oxc parser plugin comparison (Node.js vs Browser builds) Convert oxc parser to use parseSync for improved performance Nov 24, 2025
@fisker
Copy link
Owner

fisker commented Nov 24, 2025

@copilot Let's update the test command to

time (node dist/prettier/bin/prettier.cjs debug "**/*.{js,ts}" --parser=oxc-ts --plugin=./dist/plugin-oxc/index.mjs -c --with-node-modules --log-level=silent --experimental-cli --no-cache > /dev/null)
time (node dist/prettier/bin/prettier.cjs debug "**/*.{js,ts}" --parser=oxc-ts --plugin=./dist/plugin-oxc/index.browser.mjs -c --with-node-modules --log-level=silent --experimental-cli --no-cache > /dev/null)

And compare both sync and async version

Copy link
Author

Copilot AI commented Nov 24, 2025

@copilot Let's update the test command to

...

Done! Ran benchmarks with --experimental-cli --no-cache flags for both async and sync versions.

Async version (parse):

  • index.mjs: 8.236s real, 27.169s user
  • index.browser.mjs: 8.513s real, 29.168s user

Sync version (parseSync):

  • index.mjs: 7.978s real, 26.922s user (~3.1% faster)
  • index.browser.mjs: 8.435s real, 28.783s user (~0.9% faster)

The sync version shows consistent improvements, with the Node.js build gaining the most significant performance boost (258ms faster real time, 15.5% less system time).

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