Repository navigation
chore(benchmarks): codspeed #1253
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| name: CodSpeed | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
| # Lets CodSpeed replay a run when it needs a baseline. | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| benchmarks: | ||
| name: Benchmarks | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| env: | ||
| NODE_SHA: 768315cf7165e9ff9b636844b776488e9d1703fc | ||
| steps: | ||
| - name: Harden Runner | ||
| uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2 | ||
| with: | ||
| egress-policy: audit | ||
|
|
||
| - name: Setup environment | ||
| uses: nodejs/web-team/actions/setup-environment@4c0b18db11a8357664683d70ef1f27af08ecc766 | ||
| with: | ||
| use-version-file: true | ||
| pnpm: true | ||
|
|
||
| - name: Checkout Node.js sources | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| persist-credentials: false | ||
| repository: nodejs/node | ||
| ref: ${{ env.NODE_SHA }} | ||
| sparse-checkout: | | ||
| doc | ||
| lib | ||
| . | ||
| path: node | ||
|
|
||
| - name: Run benchmarks | ||
| uses: CodSpeedHQ/action@af75f77f17a054769abefaa42fe8dc2975469b5f # v5.6.3 | ||
|
avivkeller marked this conversation as resolved.
Resolved
|
||
| with: | ||
| mode: simulation,memory | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Memory here is allocations on a warm build, not the peak RSS anyone actually hits. Not sure what we want those numbers to tell us |
||
| run: node --run bench | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ Thank you for your interest in contributing to the `doc-kit` project! We welcome | |
| - [Best Practices](#best-practices) | ||
| - [Example Test File](#example-test-file) | ||
| - [Running Tests](#running-tests) | ||
| - [Benchmarks](#benchmarks) | ||
| - [Code Quality](#code-quality) | ||
| - [Linting and Formatting](#linting-and-formatting) | ||
| - [Pre-commit Hooks](#pre-commit-hooks) | ||
|
|
@@ -334,6 +335,17 @@ node --run test:coverage | |
| node --test packages/core/src/utils/__tests__/parser.test.mjs | ||
| ``` | ||
|
|
||
| ## Benchmarks | ||
|
|
||
| Generation speed and memory are measured with [CodSpeed](https://codspeed.io) | ||
| (`bench/generate.bench.mjs`), on one thread. The workflow checks `nodejs/node` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: say this is single threaded, so a flat result doesn't read as no change |
||
| out at `NODE_SHA` into `./node`, and the suite reads that directory. It runs on | ||
| every pull request and reports CPU and memory there. | ||
|
|
||
| ```bash | ||
| node --run bench | ||
| ``` | ||
|
|
||
| ## Code Quality | ||
|
|
||
| ### Linting and Formatting | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { mkdir, rm } from 'node:fs/promises'; | ||
| import path from 'node:path'; | ||
|
|
||
| import { withCodSpeed } from '@codspeed/tinybench-plugin'; | ||
| import createGenerator from '@doc-kit/core'; | ||
| import logger from '@doc-kit/core/logger/index.mjs'; | ||
| import { setConfig } from '@doc-kit/core/utils/configuration/index.mjs'; | ||
| import { Bench } from 'tinybench'; | ||
|
|
||
| logger.setLogLevel('warn'); | ||
|
|
||
| const node = path.join(import.meta.dirname, '../node'); | ||
| const at = (...parts) => path.join(node, ...parts); | ||
|
|
||
| const shared = { | ||
| threads: 1, | ||
|
avivkeller marked this conversation as resolved.
Resolved
|
||
| index: at('doc/api/index.md'), | ||
| typeMap: at('doc/type-map.json'), | ||
| changelog: at('CHANGELOG.md'), | ||
| }; | ||
|
|
||
| const docs = at('doc/api/*.md'); | ||
|
|
||
| const targets = [ | ||
|
avivkeller marked this conversation as resolved.
Resolved
|
||
| ['json', docs], | ||
| ['json-simple', docs], | ||
| ['legacy-json', docs], | ||
| ['legacy-html', docs], | ||
| ['html', docs], | ||
| ['llms-txt', docs], | ||
| ['orama-db', docs], | ||
| ['man-page', at('doc/api/cli.md')], | ||
| ['addon-verify', at('doc/api/addons.md')], | ||
| ['api-links', at('lib/*.js')], | ||
| ]; | ||
|
|
||
| const bench = withCodSpeed( | ||
| new Bench({ warmup: false, iterations: 1, time: 0, throws: true }) | ||
|
avivkeller marked this conversation as resolved.
Resolved
|
||
| ); | ||
|
|
||
| for (const [name, input] of targets) { | ||
| const output = path.join(import.meta.dirname, '../out', name); | ||
| let runGenerators; | ||
| let config; | ||
|
|
||
| bench.add(name, () => runGenerators(config), { | ||
| beforeAll: async () => { | ||
| await rm(output, { recursive: true, force: true }); | ||
| await mkdir(output, { recursive: true }); | ||
| ({ runGenerators } = createGenerator()); | ||
| config = await setConfig({ | ||
| ...shared, | ||
| target: [name], | ||
| input: [input], | ||
| output, | ||
| }); | ||
| }, | ||
| afterAll: () => rm(output, { recursive: true, force: true }), | ||
| }); | ||
| } | ||
|
|
||
| await bench.run(); | ||
|
|
||
| if (process.env.CODSPEED_ENV === undefined) { | ||
| console.table(bench.table()); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.