From 595d99969244b3d89a84c89084ae0539c0d48c70 Mon Sep 17 00:00:00 2001 From: Scott Trinh Date: Fri, 5 Jan 2024 10:01:17 -0500 Subject: [PATCH 1/3] Add attest benches for select expressions --- .github/workflows/tests.yml | 4 ++ integration-tests/lts/bench.ts | 98 ++++++++++++++++++++++++++++++ integration-tests/lts/package.json | 4 +- yarn.lock | 32 ++++++++++ 4 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 integration-tests/lts/bench.ts diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8d7779d03..c5c10fbb9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -126,6 +126,10 @@ jobs: run: | yarn workspace @edgedb/create test + - name: Run benchmarks + run: | + yarn workspace @edgedb/integration-lts run bench:types + # This job exists solely to act as the test job aggregate to be # targeted by branch policies. regression-tests: diff --git a/integration-tests/lts/bench.ts b/integration-tests/lts/bench.ts new file mode 100644 index 000000000..8c26b41f6 --- /dev/null +++ b/integration-tests/lts/bench.ts @@ -0,0 +1,98 @@ +import { bench } from "@arktype/attest"; + +import e from "./dbschema/edgeql-js"; + +bench("select: scalar", () => { + const query = e.select(e.int32(42)); + return {} as typeof query; +}).types([1263, "instantiations"]); + +bench("select: free object", () => { + const query = e.select({ meaning: e.int32(42) }); + return {} as typeof query; +}).types([2120, "instantiations"]); + +bench("select: id only", () => { + const query = e.select(e.User, () => ({ id: true })); + return {} as typeof query; +}).types([3642, "instantiations"]); + +bench("select: filtered", () => { + const query = e.select(e.User, () => ({ + filter_single: { id: e.uuid("123") }, + })); + return {} as typeof query; +}).types([5384, "instantiations"]); + +bench("select: nested", () => { + const user = e.select(e.User, () => ({ + filter_single: { id: e.uuid("123") }, + })); + const query = e.select(user, () => ({ id: true })); + + return {} as typeof query; +}).types([7412, "instantiations"]); + +bench("select: complex", () => { + const query = e.select(e.Movie, () => ({ + id: true, + characters: (char) => ({ + name: true, + "@character_name": true, + filter: e.op(char["@character_name"], "=", "Tony Stark"), + }), + })); + return {} as typeof query; +}).types([6339, "instantiations"]); + +bench("select: with filter", () => { + const query = e.select(e.Hero, (hero) => ({ + name: true, + villains: { + id: true, + name: true, + }, + filter_single: e.op(hero.name, "=", "Peter Parker"), + })); + return {} as typeof query; +}).types([98669, "instantiations"]); + +bench("select: with order", () => { + const query = e.select(e.Hero, (hero) => ({ + name: true, + villains: (v) => ({ + id: true, + name: true, + order_by: v.name, + }), + filter_single: e.op(hero.name, "=", "Peter Parker"), + })); + return {} as typeof query; +}).types([98963, "instantiations"]); + +bench("select: with limit", () => { + const query = e.select(e.Hero, (hero) => ({ + name: true, + villains: () => ({ + id: true, + name: true, + limit: 1, + }), + filter_single: e.op(hero.name, "=", "Peter Parker"), + })); + return {} as typeof query; +}).types([98694, "instantiations"]); + +bench("select: with offset", () => { + const query = e.select(e.Hero, (hero) => ({ + name: true, + villains: (v) => ({ + id: true, + name: true, + offset: 1, + }), + filter_single: e.op(hero.name, "=", "Peter Parker"), + })); + return {} as typeof query; +}).types([98730, "instantiations"]); + diff --git a/integration-tests/lts/package.json b/integration-tests/lts/package.json index a3244385c..60d17d78a 100644 --- a/integration-tests/lts/package.json +++ b/integration-tests/lts/package.json @@ -12,9 +12,11 @@ "test:cjs": "yarn generate queries --target cjs --file cjs/queries && yarn generate edgeql-js --target cjs --output-dir cjs/edgeql-js && cd cjs && node test.js", "test:mts": "yarn generate queries --target mts --file mts/queries && yarn generate edgeql-js --target mts --output-dir mts/edgeql-js && cd mts && yarn build && node dist/test.js", "test:deno": "cd deno && deno task edgeql-js && deno task queries && deno task play", - "test:ci": "tsx ./testRunner.ts" + "test:ci": "tsx ./testRunner.ts", + "bench:types": "cd ../.. && tsx integration-tests/lts/bench.ts" }, "devDependencies": { + "@arktype/attest": "^0.5.0", "@types/jest": "^29.5.2", "@types/node": "^20.3.2", "conditional-type-checks": "^1.0.6", diff --git a/yarn.lock b/yarn.lock index 062e0f809..7d46b52a5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10,6 +10,26 @@ "@jridgewell/gen-mapping" "^0.3.0" "@jridgewell/trace-mapping" "^0.3.9" +"@arktype/attest@^0.5.0": + version "0.5.0" + resolved "https://registry.yarnpkg.com/@arktype/attest/-/attest-0.5.0.tgz#bee97b89603af05ca77a5aed07cef77f746d386b" + integrity sha512-MRWnjq2rAJLhPZP9GqWHLyIOBomzxcJxHdzANNcEZV/EXdutS4YumdoHi3NEsk6zt0kscqk4reRRPnUa2zwhrQ== + dependencies: + "@arktype/fs" "0.0.10" + "@arktype/util" "0.0.16" + "@typescript/vfs" "1.5.0" + arktype latest + +"@arktype/fs@0.0.10": + version "0.0.10" + resolved "https://registry.yarnpkg.com/@arktype/fs/-/fs-0.0.10.tgz#2d728c99856554a08725b81d970bd1dc1a4e0d91" + integrity sha512-aPYLmcdS7eHUftTQOyPZRdoMWrvuk4m0LwO6dB9fwKqJTngnizWAeP0AS+tMincPhdZEahRyX0ju9Czvdm/zkQ== + +"@arktype/util@0.0.16": + version "0.0.16" + resolved "https://registry.yarnpkg.com/@arktype/util/-/util-0.0.16.tgz#2401e3ac238f135ab1fa81ad4f849d0783318534" + integrity sha512-a10hhQ5E95tV0wfi8N9/74Uo6mRDHjeGWaHsyZriq4a9srZ9AbJ3UlYUQfIaQgsxLIuMw3kdClsE/H3tMdZKvw== + "@babel/code-frame@^7.0.0", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.18.6", "@babel/code-frame@^7.21.4": version "7.21.4" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.21.4.tgz#d0fa9e4413aca81f2b23b9442797bda1826edb39" @@ -1459,6 +1479,13 @@ "@typescript-eslint/types" "5.60.1" eslint-visitor-keys "^3.3.0" +"@typescript/vfs@1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@typescript/vfs/-/vfs-1.5.0.tgz#ed942922724f9ace8c07c80b006c47e5e3833218" + integrity sha512-AJS307bPgbsZZ9ggCT3wwpg3VbTKMFNHfaY/uF0ahSkYYrPF2dSSKDNIDIQAHm9qJqbLvCsSJH7yN4Vs/CsMMg== + dependencies: + debug "^4.1.1" + "@web3-storage/multipart-parser@^1.0.0": version "1.0.0" resolved "https://registry.yarnpkg.com/@web3-storage/multipart-parser/-/multipart-parser-1.0.0.tgz#6b69dc2a32a5b207ba43e556c25cc136a56659c4" @@ -1568,6 +1595,11 @@ argparse@^2.0.1: resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38" integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q== +arktype@latest: + version "1.0.28-alpha" + resolved "https://registry.yarnpkg.com/arktype/-/arktype-1.0.28-alpha.tgz#26cb8ea9fef86a4dbae4868d6e5ba98b5f34f5b7" + integrity sha512-cjakiZXXa4+y1OL0oFk0HRjIrEwJhNNvkqXkiR53SOpyKHwSqFrjrQkY4K8MlnQybRhd/y4OG4NVDR1Ea4WDkQ== + array-flatten@1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/array-flatten/-/array-flatten-1.1.1.tgz#9a5f699051b1e7073328f2a008968b64ea2955d2" From 7773e2a688de4729e05748b534c198ccd7eb58ed Mon Sep 17 00:00:00 2001 From: Scott Trinh Date: Fri, 5 Jan 2024 10:13:02 -0500 Subject: [PATCH 2/3] Run benchmarks as part of the LTS test block --- .github/workflows/tests.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c5c10fbb9..6486c67b9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -107,6 +107,7 @@ jobs: if: ${{ matrix.edgedb-version == '3' || matrix.edgedb-version == 'stable' || matrix.edgedb-version == 'nightly' }} run: | yarn workspace @edgedb/integration-lts test:ci + yarn workspace @edgedb/integration-lts run bench:types - name: Run query builder integration tests stable if: ${{ matrix.edgedb-version == 'stable' || matrix.edgedb-version == 'nightly' }} @@ -126,10 +127,6 @@ jobs: run: | yarn workspace @edgedb/create test - - name: Run benchmarks - run: | - yarn workspace @edgedb/integration-lts run bench:types - # This job exists solely to act as the test job aggregate to be # targeted by branch policies. regression-tests: From 0d3293b9b2c277bd20f14b39710ab55bba7d3539 Mon Sep 17 00:00:00 2001 From: Scott Trinh Date: Fri, 5 Jan 2024 10:14:32 -0500 Subject: [PATCH 3/3] Bump to 20 now that it's LTS --- .github/workflows/tests.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6486c67b9..78e9379b7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,16 +21,16 @@ jobs: edgedb-version: ["stable"] include: - os: ubuntu-latest - node-version: "18" + node-version: "20" edgedb-version: "nightly" - os: ubuntu-latest - node-version: "18" + node-version: "20" edgedb-version: "3" - os: ubuntu-latest - node-version: "18" + node-version: "20" edgedb-version: "2" - os: macos-latest - node-version: "18" + node-version: "20" edgedb-version: "stable" steps: