-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: Benchmark expression evaluation
- Loading branch information
Showing
7 changed files
with
173 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Benchmark workflow package | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- 'packages/workflow/**' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
benchmark: | ||
name: Benchmark | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4.1.1 | ||
|
||
- run: corepack enable | ||
|
||
- uses: actions/setup-node@v4.0.1 | ||
with: | ||
node-version: 18.x | ||
cache: pnpm | ||
|
||
- run: pnpm install --frozen-lockfile | ||
|
||
- name: Build | ||
if: ${{ inputs.cacheKey == '' }} | ||
run: pnpm build:backend | ||
|
||
- name: Restore cached build artifacts | ||
if: ${{ inputs.cacheKey != '' }} | ||
uses: actions/cache/restore@v4.0.0 | ||
with: | ||
path: ./packages/**/dist | ||
key: ${{ inputs.cacheKey }} | ||
|
||
- name: Build benchmarks | ||
working-directory: packages/workflow | ||
run: pnpm benchmark:build | ||
|
||
- name: Benchmark workflow package | ||
uses: CodSpeedHQ/action@v2 | ||
with: | ||
working-directory: packages/workflow | ||
run: pnpm benchmark:run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Bench } from 'tinybench'; | ||
import { withCodSpeed } from '@codspeed/tinybench-plugin'; | ||
import { baseFixtures } from './ExpressionFixtures/base'; | ||
import { evaluate } from './evaluate'; | ||
import type { INodeExecutionData } from '@/index'; | ||
|
||
function addExpressionEvaluationTasks(bench: Bench) { | ||
for (const fixture of baseFixtures) { | ||
for (const test of fixture.tests) { | ||
if ('error' in test) continue; | ||
|
||
if (test.type === 'evaluation') { | ||
const input = test.input.map((d) => ({ json: d })) as INodeExecutionData[]; | ||
bench.add(fixture.expression, () => evaluate(fixture.expression, input)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
async function main() { | ||
const bench = withCodSpeed(new Bench()); | ||
|
||
addExpressionEvaluationTasks(bench); | ||
|
||
await bench.warmup(); | ||
await bench.run(); | ||
|
||
console.table(bench.table()); | ||
} | ||
|
||
void main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { workflow } from './ExpressionExtensions/Helpers'; | ||
import type { INodeExecutionData } from '@/Interfaces'; | ||
|
||
export const evaluate = (expression: string, data: INodeExecutionData[] = []) => { | ||
return workflow.expression.getParameterValue(expression, null, 0, 0, 'node', data, 'manual', {}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"extends": ["./tsconfig.json", "../../tsconfig.build.json"], | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"tsBuildInfoFile": "dist/benchmark.tsbuildinfo", | ||
"baseUrl": ".", | ||
"paths": { | ||
"@/*": ["./src/*"] | ||
} | ||
}, | ||
"include": ["test/**/*.ts"], | ||
"exclude": ["test/**/*.test.ts"] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.