Skip to content

Commit

Permalink
Bump TypeScript to benchmark type perf regression
Browse files Browse the repository at this point in the history
  • Loading branch information
scotttrinh committed Apr 3, 2024
1 parent a5f0db8 commit 5f2906d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 10 deletions.
61 changes: 51 additions & 10 deletions integration-tests/lts/bench.ts
Expand Up @@ -2,27 +2,68 @@ import { bench } from "@arktype/attest";

import e from "./dbschema/edgeql-js";

bench("scalar literal", () => {
bench("e.literal: scalar", () => {
const lit = e.literal(e.int32, 42);
return {} as typeof lit;
}).types([4468, "instantiations"]);

bench("e.int32: scalar", () => {
const lit = e.int32(42);
return {} as typeof lit;
}).types([558, "instantiations"]);

bench("array literal", () => {
bench("e.str: scalar", () => {
const lit = e.str("abcd");
return {} as typeof lit;
}).types([897, "instantiations"]);

bench("e.literal: array literal", () => {
const lit = e.literal(e.array(e.str), ["abcd"]);
return {} as typeof lit;
}).types([4116, "instantiations"]);
}).types([7568, "instantiations"]);

bench("named tuple literal", () => {
bench("e.array: array literal", () => {
const lit = e.array([e.str("abcd")]);
return {} as typeof lit;
}).types([2606, "instantiations"]);

bench("e.literal: named tuple literal", () => {
const lit = e.literal(e.tuple({ str: e.str }), {
str: "asdf",
});
return {} as typeof lit;
}).types([13063, "instantiations"]);
}).types([16528, "instantiations"]);

bench("e.tuple: named tuple literal", () => {
const lit = e.tuple({ str: e.str("asdf") });
return {} as typeof lit;
}).types([9831, "instantiations"]);

bench("tuple literal", () => {
bench("e.literal: tuple literal", () => {
const lit = e.literal(e.tuple([e.str, e.int32]), ["asdf", 42]);
return {} as typeof lit;
}).types([9668, "instantiations"]);
}).types([13125, "instantiations"]);

bench("e.tuple: tuple literal", () => {
const lit = e.tuple([e.str("asdf"), e.int32(42)]);
return {} as typeof lit;
}).types([4889, "instantiations"]);

bench("e.literal: array of tuples", () => {
const lit = e.literal(e.array(e.tuple([e.str, e.int32])), [
["asdf", 42],
["qwer", 43],
]);
return {} as typeof lit;
}).types([15721, "instantiations"]);

bench("e.array: array of tuples", () => {
const lit = e.array([
e.tuple([e.str("asdf"), e.int32(42)]),
e.tuple([e.str("qwer"), e.int32(43)]),
]);
return {} as typeof lit;
}).types([22894, "instantiations"]);

bench("base type: array", () => {
const baseType = e.array(e.str);
Expand Down Expand Up @@ -54,7 +95,7 @@ bench("select: filtered", () => {
filter_single: { id: e.uuid("123") },
}));
return {} as typeof query;
}).types([5046, "instantiations"]);
}).types([5039, "instantiations"]);

bench("select: nested", () => {
const user = e.select(e.User, () => ({
Expand All @@ -63,7 +104,7 @@ bench("select: nested", () => {
const query = e.select(user, () => ({ id: true }));

return {} as typeof query;
}).types([6064, "instantiations"]);
}).types([6057, "instantiations"]);

bench("select: complex", () => {
const query = e.select(e.Movie, () => ({
Expand Down Expand Up @@ -140,4 +181,4 @@ bench("params select", () => {
}))
);
return {} as typeof query;
}).types([12005, "instantiations"]);
}).types([12010, "instantiations"]);
1 change: 1 addition & 0 deletions packages/generate/src/syntax/literal.ts
Expand Up @@ -35,6 +35,7 @@ export function literal<T extends BaseType>(
__element__: type,
__cardinality__: Cardinality.One,
__kind__: ExpressionKind.Literal,
// @ts-expect-error: Type instantiation error
__value__: value,
}) as any;
}
Expand Down

0 comments on commit 5f2906d

Please sign in to comment.