Skip to content

Commit da90074

Browse files
authored
feat: setup attest for type benchmarking (#142)
This PR is setting `@ark/attest` up for us to improve our typechecking performance.
2 parents 216bbf6 + 431242e commit da90074

11 files changed

Lines changed: 340 additions & 5 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ jobs:
3939
- name: typecheck
4040
run: pnpm typecheck
4141

42+
- name: run benchmarks
43+
run: pnpm bench:types -- --benchErrorOnThresholdExceeded --benchPercentThreshold 10
44+
4245
- name: test
4346
run: pnpm test --coverage
4447

45-
4648
- name: upload coverage reports to codecov
4749
uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # v5.4.0
4850
with:

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"test": "vitest run",
2020
"test:watch": "vitest",
2121
"test:ui": "vitest --ui",
22+
"bench:types": "turbo run bench:types",
2223
"typecheck": "turbo run typecheck"
2324
},
2425
"devDependencies": {
@@ -29,8 +30,10 @@
2930
"@vitest/ui": "catalog:monorepo",
3031
"eslint": "catalog:dev",
3132
"msw": "catalog:monorepo",
33+
"@ark/attest": "catalog:monorepo",
3234
"turbo": "catalog:monorepo",
3335
"typescript": "catalog:dev",
34-
"vitest": "catalog:dev"
36+
"vitest": "catalog:dev",
37+
"tsx": "catalog:monorepo"
3538
}
3639
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import { bench } from "@ark/attest";
2+
import { type } from "arktype";
3+
import { createSourceAdapter } from "../../src/builders/source-builder/builder";
4+
5+
bench("source adapter builder", () => {
6+
createSourceAdapter({
7+
type: "metadata",
8+
transformerOutputSchema: type({
9+
hello: "string",
10+
world: "string",
11+
}),
12+
fallback: {
13+
hello: "hello",
14+
world: "world",
15+
},
16+
persistence: {
17+
schemas: {},
18+
},
19+
});
20+
}).types([19921, "instantiations"]);
21+
22+
bench("source adapter with transforms", () => {
23+
createSourceAdapter({
24+
type: "metadata",
25+
transformerOutputSchema: type({
26+
hello: "string",
27+
world: "string",
28+
}),
29+
fallback: {
30+
hello: "hello",
31+
world: "world",
32+
},
33+
persistence: {
34+
schemas: {},
35+
},
36+
}).withTransform(
37+
() => true,
38+
(builder) => {
39+
return builder
40+
.urls(() => "v14")
41+
.parser("generic")
42+
.transform((_, data) => data)
43+
.output((_, data) => {
44+
return {
45+
hello: data.lines.join(","),
46+
world: `${data.totalLines}`,
47+
};
48+
});
49+
},
50+
).build();
51+
}).types([21691, "instantiations"]);
52+
53+
bench("source adapter with multiple transforms", () => {
54+
createSourceAdapter({
55+
type: "metadata",
56+
transformerOutputSchema: type({
57+
hello: "string",
58+
world: "string",
59+
}),
60+
fallback: {
61+
hello: "hello",
62+
world: "world",
63+
},
64+
persistence: {
65+
schemas: {},
66+
},
67+
})
68+
.withTransform(
69+
() => true,
70+
(builder) => {
71+
return builder
72+
.urls(() => "v14")
73+
.parser("generic")
74+
.transform((_, data) => data)
75+
.output((_, data) => {
76+
return {
77+
hello: data.lines.join(","),
78+
world: `${data.totalLines}`,
79+
};
80+
});
81+
},
82+
)
83+
.withTransform(
84+
() => true,
85+
(builder) => {
86+
return builder
87+
.urls(() => "v14")
88+
.parser("generic")
89+
.transform((_, data) => data)
90+
.output((_, data) => {
91+
return {
92+
hello: data.lines.join(","),
93+
world: `${data.totalLines}`,
94+
};
95+
});
96+
},
97+
)
98+
.withTransform(
99+
() => true,
100+
(builder) => {
101+
return builder
102+
.urls(() => "v14")
103+
.parser("generic")
104+
.transform((_, data) => data)
105+
.output((_, data) => {
106+
return {
107+
hello: data.lines.join(","),
108+
world: `${data.totalLines}`,
109+
};
110+
});
111+
},
112+
)
113+
.build();
114+
}).types([25705, "instantiations"]);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "./builders/source-builder.ts-bench.ts";

packages/adapters/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"dev": "tsdown --watch",
3434
"clean": "git clean -xdf dist node_modules",
3535
"lint": "eslint .",
36-
"typecheck": "tsc --noEmit"
36+
"typecheck": "tsc --noEmit",
37+
"bench:types": "tsx ./.ts-benchmarks/index.ts"
3738
},
3839
"dependencies": {
3940
"@mojis/internal-utils": "workspace:*",

packages/adapters/tsconfig.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{
22
"extends": "../../tsconfig.base.json",
3-
"include": ["src/**/*", "*.ts", "test"]
3+
"include": [
4+
"src/**/*",
5+
"*.ts",
6+
"test",
7+
".ts-benchmarks/**/*"
8+
]
49
}

0 commit comments

Comments
 (0)