Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,65 @@ jobs:
with:
token: ${{ secrets.CODSPEED_TOKEN }}
run: cargo codspeed run

# Build NAPI parser
build-parser-napi:
name: Build NAPI parser
runs-on: ubuntu-latest
steps:
- name: Checkout Branch
uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1

- uses: oxc-project/setup-rust@cd82e1efec7fef815e2c23d296756f31c7cdc03d # v1.0.0
with:
cache-key: benchmark-parser-napi
save-cache: ${{ github.ref_name == 'main' }}

- uses: ./.github/actions/pnpm

- name: Build benchmark
run: |
cd napi/parser;
pnpm run build;

- name: Upload Binary
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
with:
if-no-files-found: error
name: benchmark-parser-napi
path: ./napi/parser/parser.*.node
retention-days: 1

# Run NAPI parser benchmark.
# Shard into multiple jobs as it's so slow.
benchmark-parser-napi:
name: Benchmark NAPI parser
needs: build-parser-napi
runs-on: ubuntu-latest
strategy:
matrix:
# Skip the slowest benchmarks
shard: [1, 3, 4, 5, 6, 7]
steps:
- name: Checkout Branch
uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1

- name: Download Binary
uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4.1.9
with:
name: benchmark-parser-napi
path: ./napi/parser

- uses: ./.github/actions/pnpm

- name: Run benchmark
uses: CodSpeedHQ/action@63ae6025a0ffee97d7736a37c9192dbd6ed4e75f # v3.4.0
timeout-minutes: 30
env:
SHARD: ${{ matrix.shard }}
with:
token: ${{ secrets.CODSPEED_TOKEN }}
run: |
mkdir -p target;
cd napi/parser;
pnpm run bench;
42 changes: 30 additions & 12 deletions napi/parser/bench.bench.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,28 @@ import { bench } from 'vitest';
import { parseSync } from './index.js';

// Same fixtures as used in Rust parser benchmarks
const fixtureUrls = [
let fixtureUrls = [
'https://raw.githubusercontent.com/microsoft/TypeScript/v5.3.3/src/compiler/checker.ts',
'https://raw.githubusercontent.com/oxc-project/benchmark-files/main/cal.com.tsx',
'https://raw.githubusercontent.com/oxc-project/benchmark-files/main/RadixUIAdoptionSection.jsx',
'https://cdn.jsdelivr.net/npm/pdfjs-dist@4.0.269/build/pdf.mjs',
'https://cdn.jsdelivr.net/npm/antd@5.12.5/dist/antd.js',
];

// For sharding in CI - specify single fixture to run benchmarks on
let skipStandard = false, skipRaw = false;
let shard = process.env.SHARD;
if (shard) {
shard *= 1;
if (shard % 2 === 0) {
skipRaw = true;
} else {
skipStandard = true;
shard--;
}
fixtureUrls = [fixtureUrls[shard / 2]];
}

// Same directory as Rust benchmarks use for downloaded files
// to avoid re-downloading if Rust benchmarks already downloaded
const cacheDirPath = pathJoin(import.meta.dirname, '../../target');
Expand All @@ -35,15 +49,19 @@ const fixtures = await Promise.all(fixtureUrls.map(async (url) => {

// Run benchmarks
for (const { filename, code } of fixtures) {
bench(`parser_napi[${filename}]`, () => {
const ret = parseSync(filename, code);
// Read returned object's properties to execute getters which deserialize
const { program, comments, module, errors } = ret;
});

bench(`parser_napi_raw[${filename}]`, () => {
const ret = parseSync(filename, code, { experimentalRawTransfer: true });
// Read returned object's properties to execute getters
const { program, comments, module, errors } = ret;
});
if (!skipStandard) {
bench(`parser_napi[${filename}]`, () => {
const ret = parseSync(filename, code);
// Read returned object's properties to execute getters which deserialize
const { program, comments, module, errors } = ret;
});
}

if (!skipRaw) {
bench(`parser_napi_raw[${filename}]`, () => {
const ret = parseSync(filename, code, { experimentalRawTransfer: true });
// Read returned object's properties to execute getters
const { program, comments, module, errors } = ret;
});
}
}
1 change: 1 addition & 0 deletions napi/parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@oxc-project/types": "workspace:^"
},
"devDependencies": {
"@codspeed/vitest-plugin": "^4.0.0",
"vitest": "catalog:"
}
}
9 changes: 9 additions & 0 deletions napi/parser/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Enable Codspeed plugin in CI only
const config = {};
if (process.env.CI) {
const codspeedPlugin = (await import('@codspeed/vitest-plugin')).default;
// @ts-ignore
config.plugins = [codspeedPlugin()];
}

export default config;
96 changes: 96 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading