Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(napi): add oxc-parser to benchmarks #2724

Merged
merged 1 commit into from Mar 15, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion .github/workflows/benchmark.yml
Expand Up @@ -38,6 +38,12 @@ jobs:
shared-key: 'benchmark'
save-cache: ${{ github.ref_name == 'main' }}

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'

- name: Install codspeed
uses: taiki-e/install-action@v2
with:
Expand All @@ -59,9 +65,19 @@ jobs:
mv target/release/deps/codegen_sourcemap-* target/codspeed/oxc_benchmark
rm -rf target/codspeed/oxc_benchmark/*.d

- name: Build NAPI benchmark
working-directory: ./napi/parser
run: |
corepack enable
pnpm install
pnpm run build

- name: Run benchmark
uses: CodSpeedHQ/action@v2
timeout-minutes: 30
with:
run: cargo codspeed run
run: |
cargo codspeed run
cd napi/parser
pnpm run bench
token: ${{ secrets.CODSPEED_TOKEN }}
9 changes: 6 additions & 3 deletions napi/parser/package.json
Expand Up @@ -3,17 +3,20 @@
"private": true,
"scripts": {
"build": "napi build --platform --release",
"test": "node test.mjs"
"test": "node test.mjs",
"bench": "vitest bench"
},
"devDependencies": {
"@codspeed/vitest-plugin": "^3.1.0",
"@napi-rs/cli": "^2.18.0",
"es-module-lexer": "^1.4.1",
"flatbuffers": "^23.5.26"
"flatbuffers": "^23.5.26",
"vitest": "^1.3.1"
},
"engines": {
"node": ">=14.*"
},
"packageManager": "pnpm@8.2.0",
"packageManager": "pnpm@8.15.4+sha256.cea6d0bdf2de3a0549582da3983c70c92ffc577ff4410cbf190817ddc35137c2",
"napi": {
"name": "parser",
"triples": {
Expand Down
48 changes: 48 additions & 0 deletions napi/parser/parse.bench.mjs
@@ -0,0 +1,48 @@
import {fileURLToPath} from 'url';
import {join as pathJoin} from 'path';
import {readFile, writeFile} from 'fs/promises';
import assert from 'assert';
import {bench} from 'vitest';
import {parseSync} from './index.js';

const urls = [
// TypeScript syntax (2.81MB)
'https://raw.githubusercontent.com/microsoft/TypeScript/v5.3.3/src/compiler/checker.ts',
// Real world app tsx (1.0M)
'https://raw.githubusercontent.com/oxc-project/benchmark-files/main/cal.com.tsx',
// Real world content-heavy app jsx (3K)
'https://raw.githubusercontent.com/oxc-project/benchmark-files/main/RadixUIAdoptionSection.jsx',
// Heavy with classes (554K)
'https://cdn.jsdelivr.net/npm/pdfjs-dist@4.0.269/build/pdf.mjs',
// ES5 (3.9M)
'https://cdn.jsdelivr.net/npm/antd@5.12.5/dist/antd.js',
];

// Same directory as Rust benchmarks use for downloaded files
const cacheDirPath = pathJoin(fileURLToPath(import.meta.url), '../../../target');

const files = await Promise.all(urls.map(async (url) => {
const filename = url.split('/').at(-1),
path = pathJoin(cacheDirPath, filename);

let code;
try {
code = await readFile(path, 'utf8');
console.log('Found cached file:', filename);
} catch {
console.log('Downloading:', filename);
const res = await fetch(url);
code = await res.text();
await writeFile(path, code);
}

return {filename, code};
}));

for (const {filename, code} of files) {
bench(`parser(napi)[${filename}]`, () => {
const res = parseSync(code, {sourceFilename: filename});
assert(res.errors.length === 0);
JSON.parse(res.program);
});
}