Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhacks committed Mar 1, 2025
1 parent 33aacdd commit 8df594e
Show file tree
Hide file tree
Showing 85 changed files with 62,124 additions and 6,878 deletions.
11 changes: 8 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@
"type": "node",
"runtimeExecutable": "/Users/colinmcd94/.nvm/versions/node/v22.13.0/bin/node",
"request": "launch",
"name": "Run play.ts",
"name": "node",
"args": [],
"runtimeArgs": ["--experimental-strip-types"],
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/play.ts",
"outFiles": ["${workspaceFolder}/**/*.js"]
// "program": "${workspaceFolder}/play.ts",
"program": "${file}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"

// "outFiles": ["${workspaceFolder}/**/*.js"]
},
{
"name": "tsx",
"type": "node",
"request": "launch",
"runtimeArgs": ["--cpu-prof", "--conditions=@zod/source"],

// Debug current file in VSCode
"program": "${file}",
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"files.exclude": {
"./scratch": false,
"**/.tshy-build": true,
"**/dist": true,
"**/lib": true
},
"search.exclude": {
Expand Down
3 changes: 2 additions & 1 deletion biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"noUnusedTemplateLiteral": "off", // why is this even a best practice?
"noParameterAssign": "off", // required for performant coercion in _parse
"noNonNullAssertion": "off",
"useTemplate": "off"
"useTemplate": "off",
"noUselessElse": "off"
},
"correctness": {
"noUnusedImports": {
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@
"tslib": "^2.8.1",
"tsx": "^4.19.2",
"typescript": "5.5.3",
"vitest": "^2.0.0"
"vitest": "^2.0.0",
"@zod/core": "^3.23.8",
"zod": "^3.23.7",
"zod-mini": "^3.23.8",
"zod3": "npm:zod@^3.24.0"
},
"lint-staged": {
"src/*.ts": ["biome format --write", "biome lint --write"],
Expand All @@ -62,6 +66,7 @@
"dev:watch": "tsx --conditions @zod/source --watch",
"dev:play": "pnpm dev playground.ts",
"bench": "tsx --conditions @zod/source packages/benchmarks/index.ts",
"moltar": "pnpm bench object-moltar",
"prepare": "husky install",
"publish:jsr": "jsr publish --dry-run",
"bundle:rollup": "rollup -c",
Expand Down
25 changes: 5 additions & 20 deletions packages/benchmarks/ab-parse-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const v3schema = z3.object({
a: z3.string(),
b: z3.string(),
c: z3.string(),
// d: z.string(),
// e: z.string(),
// f: z.string(),
// d: z3.string(),
// e: z3.string(),
// f: z3.string(),
// g: z.string(),
// h: z.string(),
// i: z.string(),
Expand Down Expand Up @@ -68,27 +68,12 @@ const DATA = makeData(1000, () => ({
// r: randomString(10),
}));

// console.log(z.parse(schema, DATA[0]));
console.log(
schema.safeParse(DATA[0], {
skipFast: true,
})
);
console.log(schema.safeParse(DATA[0]));
// console.log(z.safeParseC(schema, DATA[0]));

// console.log(z.parse2(schema, DATA[0]));
// console.log(z.parse3(schema, DATA[0]));
console.log(v3schema.safeParse(DATA[0]));

const bench = metabench("AB test: objects", {
// _parseC() {
// for (const _ of DATA) z.safeParseC(schema, _);
// },
// no_fastpass() {
// for (const _ of DATA) z.safeParse(schema, _, { skipFast: true });
// },
zod4() {
for (const _ of DATA) z.safeParse(schema, _);
for (const _ of DATA) schema.safeParse(_);
},
zod3() {
for (const _ of DATA) v3schema.safeParse(_);
Expand Down
2 changes: 1 addition & 1 deletion packages/benchmarks/metabench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Bench } from "tinybench";
import { formatNumber } from "./benchUtil.js";

type BENCH = "tinybench" | "benchmarkjs" | "mitata";
const BENCH: BENCH = (process.env.BENCH as BENCH) || "benchmarkjs";
const BENCH: BENCH = (process.env.BENCH as BENCH) || "mitata";

type Benchmarks<T = unknown> = { [k: string]: (d: T) => any };
export function metabench<D>(name: string, benchmarks?: Benchmarks<D>): Metabench {
Expand Down
5 changes: 4 additions & 1 deletion packages/effect-plugin/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "../src/index.js";

import { Cause, Effect, Exit } from "effect";
import { describe, expect, test } from "vitest";
import { describe, expect, test, expectTypeOf } from "vitest";
import * as z from "zod";

const syncSchema = z.string();
Expand Down Expand Up @@ -47,4 +47,7 @@ describe("Schema validation tests", () => {
}
}
});

expectTypeOf<z.infer<typeof syncSchema>>().toEqualTypeOf<string>();
expectTypeOf<z.infer<typeof asyncSchema>>().toEqualTypeOf<string>();
});
4 changes: 2 additions & 2 deletions packages/tsperf/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ generate({
path: "src/index.ts",
// ...ZOD3,
...ZOD,
schemaType: "z.interface",
schemaType: "z.object",
// ...ARKTYPE,
// ...VALIBOT,
numSchemas: 100,
numSchemas: 1000,
methods: [""],
numKeys: 10,
numRefs: 0,
Expand Down
4 changes: 2 additions & 2 deletions packages/tsperf/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ generate({
path: "src/index.ts",
// ...ZOD3,
...ZOD,
schemaType: "z.interface",
schemaType: "z.object",
// ...ARKTYPE,
// ...VALIBOT,

numSchemas: 100,
numSchemas: 1000,
methods: [""],
numKeys: 10,
numRefs: 0,
Expand Down
Loading

0 comments on commit 8df594e

Please sign in to comment.