From 3e91d443a34d26c6bdc3d6c5ada191a80526e0ec Mon Sep 17 00:00:00 2001 From: Scott Trinh Date: Fri, 5 Jan 2024 16:30:43 -0500 Subject: [PATCH 01/10] Some continued performance improvements: - Delta: 0.00% - Delta: 0.00% - Delta: -3.54% - Delta: -2.27% - Delta: -16.53% - Delta: -0.02% - Delta: -1.39% - Delta: -1.33% - Delta: -1.39% - Delta: -1.38% --- packages/generate/src/syntax/select.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/generate/src/syntax/select.ts b/packages/generate/src/syntax/select.ts index 2b2c5aea8..7a20a04d7 100644 --- a/packages/generate/src/syntax/select.ts +++ b/packages/generate/src/syntax/select.ts @@ -881,6 +881,7 @@ export function select( export function select< Expr extends ObjectTypeExpression, Element extends Expr["__element__"], + ElementName extends `${Element["__name__"]}`, Scope extends $scopify & $linkPropify<{ [k in keyof Expr]: k extends "__cardinality__" @@ -888,17 +889,19 @@ export function select< : Expr[k]; }>, Shape extends objectTypeToSelectShape & SelectModifiers, - Modifiers extends UnknownSelectModifiers = Pick + SelectCard extends ComputeSelectCardinality, + SelectShape extends normaliseShape, + Modifiers extends UnknownSelectModifiers = Pick, >( expr: Expr, shape: (scope: Scope) => Readonly ): $expr_Select<{ __element__: ObjectType< - `${Element["__name__"]}`, // _shape + ElementName, Element["__pointers__"], - Omit, SelectModifierNames> + SelectShape >; - __cardinality__: ComputeSelectCardinality; + __cardinality__: SelectCard; }>; /* From 31ac57469a500f30b27fea35de478879d23a6acc Mon Sep 17 00:00:00 2001 From: Scott Trinh Date: Fri, 5 Jan 2024 17:15:41 -0500 Subject: [PATCH 02/10] In scalar constructors, prefer Omit - Delta: -15.40% - Delta: -7.44% - Delta: -4.43% - Delta: -3.57% - Delta: -2.77% - Delta: -16.90% - Delta: -1.48% - Delta: -2.57% - Delta: -2.46% - Delta: -2.56% - Delta: -2.55% --- packages/generate/src/syntax/typesystem.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/generate/src/syntax/typesystem.ts b/packages/generate/src/syntax/typesystem.ts index a559a6470..9499b9d20 100644 --- a/packages/generate/src/syntax/typesystem.ts +++ b/packages/generate/src/syntax/typesystem.ts @@ -31,8 +31,8 @@ export type BaseTypeTuple = typeutil.tupleOf; export interface ScalarType< Name extends string = string, - TsType extends any = any, - TsArgType extends any = TsType, + TsType = any, + TsArgType = TsType, TsConstType extends TsType = TsType > extends BaseType { __kind__: TypeKind.scalar; @@ -47,13 +47,14 @@ export type scalarTypeWithConstructor< ExtraTsTypes = never > = S & { // tslint:disable-next-line - (val: T): $expr_Literal< - ScalarType< - S["__name__"], - S["__tstype__"], - S["__tsargtype__"], - T extends S["__tstype__"] ? T : S["__tstype__"] - > + < + T extends S["__tstype__"] | ExtraTsTypes, + >( + val: T + ): $expr_Literal< + Omit & { + __tsconsttype__: T extends S["__tstype__"] ? T : S["__tstype__"]; + } >; }; From d7dd187a2ceb74ca2b445b3c4ac35db3c2af8497 Mon Sep 17 00:00:00 2001 From: Scott Trinh Date: Mon, 8 Jan 2024 10:30:06 -0500 Subject: [PATCH 03/10] Store the pointer prop in objectTypeToSelectShape - Delta: -15.40% - Delta: -7.44% - Delta: -4.43% - Delta: -5.01% - Delta: -5.81% - Delta: -19.64% - Delta: -3.00% - Delta: -5.08% - Delta: -4.37% - Delta: -4.54% - Delta: -4.52% --- packages/generate/src/syntax/select.ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/generate/src/syntax/select.ts b/packages/generate/src/syntax/select.ts index 7a20a04d7..3999223e6 100644 --- a/packages/generate/src/syntax/select.ts +++ b/packages/generate/src/syntax/select.ts @@ -762,21 +762,24 @@ export type linkDescToSelectElement = // pointers -> links // links -> target object type // links -> link properties -export type objectTypeToSelectShape = +export type objectTypeToSelectShape< + T extends ObjectType = ObjectType, + Pointers extends ObjectTypePointers = T["__pointers__"] +> = // ObjectType extends T // ? {[k: string]: unknown} // : Partial<{ - [k in keyof T["__pointers__"]]: T["__pointers__"][k] extends PropertyDesc + [k in keyof Pointers]: Pointers[k] extends PropertyDesc ? | boolean | TypeSet< - T["__pointers__"][k]["target"], - cardutil.assignable + Pointers[k]["target"], + cardutil.assignable > | $expr_PolyShapeElement - : T["__pointers__"][k] extends LinkDesc - ? linkDescToSelectElement + : Pointers[k] extends LinkDesc + ? linkDescToSelectElement : any; }> & { [k: string]: unknown }; @@ -891,16 +894,12 @@ export function select< Shape extends objectTypeToSelectShape & SelectModifiers, SelectCard extends ComputeSelectCardinality, SelectShape extends normaliseShape, - Modifiers extends UnknownSelectModifiers = Pick, + Modifiers extends UnknownSelectModifiers = Pick >( expr: Expr, shape: (scope: Scope) => Readonly ): $expr_Select<{ - __element__: ObjectType< - ElementName, - Element["__pointers__"], - SelectShape - >; + __element__: ObjectType; __cardinality__: SelectCard; }>; /* From 4cdfb770dc642b5d2d05265ba28c16dfde520a84 Mon Sep 17 00:00:00 2001 From: Scott Trinh Date: Mon, 8 Jan 2024 11:02:13 -0500 Subject: [PATCH 04/10] Improve other select overload - Delta: -15.40% - Delta: -8.55% - Delta: -5.09% - Delta: -5.01% - Delta: -5.81% - Delta: -19.64% - Delta: -3.00% - Delta: -5.08% - Delta: -4.37% - Delta: -4.54% - Delta: -4.52% --- packages/generate/src/syntax/select.ts | 34 ++++++++++++++------------ 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/packages/generate/src/syntax/select.ts b/packages/generate/src/syntax/select.ts index 3999223e6..237c024e4 100644 --- a/packages/generate/src/syntax/select.ts +++ b/packages/generate/src/syntax/select.ts @@ -353,10 +353,10 @@ export interface SelectModifierMethods { export type InferOffsetLimitCardinality< Card extends Cardinality, - Modifers extends UnknownSelectModifiers -> = Modifers["limit"] extends number | LimitExpression + Modifiers extends UnknownSelectModifiers +> = Modifiers["limit"] extends number | LimitExpression ? cardutil.overrideLowerBound - : Modifers["offset"] extends number | OffsetExpression + : Modifiers["offset"] extends number | OffsetExpression ? cardutil.overrideLowerBound : Card; @@ -741,7 +741,7 @@ export type linkDescToLinkProps = { export type pointersToObjectType

= ObjectType< string, P, - {} + object >; type linkDescToShape = objectTypeToSelectShape< @@ -749,6 +749,7 @@ type linkDescToShape = objectTypeToSelectShape< > & objectTypeToSelectShape> & SelectModifiers; + export type linkDescToSelectElement = | boolean // | pointerToCastableExpression @@ -868,15 +869,18 @@ function $shape(_a: unknown, b: (...args: any) => any) { } export { $shape as shape }; -export function select( +export function select< + Expr extends ObjectTypeExpression, + Element extends Expr["__element__"], + ElementName extends `${Element["__name__"]}`, + ElementPointers extends Element["__pointers__"], + ElementShape extends Element["__shape__"], + Card extends Expr["__cardinality__"] +>( expr: Expr ): $expr_Select<{ - __element__: ObjectType< - `${Expr["__element__"]["__name__"]}`, // _shape - Expr["__element__"]["__pointers__"], - Expr["__element__"]["__shape__"] // {id: true} - >; - __cardinality__: Expr["__cardinality__"]; + __element__: ObjectType; + __cardinality__: Card; }>; export function select( expr: Expr @@ -884,16 +888,16 @@ export function select( export function select< Expr extends ObjectTypeExpression, Element extends Expr["__element__"], - ElementName extends `${Element["__name__"]}`, + Shape extends objectTypeToSelectShape & SelectModifiers, + SelectCard extends ComputeSelectCardinality, + SelectShape extends normaliseShape, Scope extends $scopify & $linkPropify<{ [k in keyof Expr]: k extends "__cardinality__" ? Cardinality.One : Expr[k]; }>, - Shape extends objectTypeToSelectShape & SelectModifiers, - SelectCard extends ComputeSelectCardinality, - SelectShape extends normaliseShape, + ElementName extends `${Element["__name__"]}`, Modifiers extends UnknownSelectModifiers = Pick >( expr: Expr, From c0ca8cd3baef58af69590ae897f14822e263fb98 Mon Sep 17 00:00:00 2001 From: Scott Trinh Date: Mon, 8 Jan 2024 12:28:36 -0500 Subject: [PATCH 05/10] Update benchmarks --- integration-tests/lts/bench.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/integration-tests/lts/bench.ts b/integration-tests/lts/bench.ts index c6e670db5..77aa5bdec 100644 --- a/integration-tests/lts/bench.ts +++ b/integration-tests/lts/bench.ts @@ -5,7 +5,7 @@ import e from "./dbschema/edgeql-js"; bench("scalar literal", () => { const lit = e.int32(42); return {} as typeof lit; -}).types([656, "instantiations"]); +}).types([555, "instantiations"]); bench("array literal", () => { const lit = e.literal(e.array(e.str), ["abcd"]); @@ -32,24 +32,24 @@ bench("base type: named tuple", () => { bench("select: scalar", () => { const query = e.select(e.int32(42)); return {} as typeof query; -}).types([1263, "instantiations"]); +}).types([1155, "instantiations"]); bench("select: free object", () => { const query = e.select({ meaning: e.int32(42) }); return {} as typeof query; -}).types([2120, "instantiations"]); +}).types([2012, "instantiations"]); bench("select: id only", () => { const query = e.select(e.User, () => ({ id: true })); return {} as typeof query; -}).types([4105, "instantiations"]); +}).types([3910, "instantiations"]); bench("select: filtered", () => { const query = e.select(e.User, () => ({ filter_single: { id: e.uuid("123") }, })); return {} as typeof query; -}).types([5596, "instantiations"]); +}).types([5283, "instantiations"]); bench("select: nested", () => { const user = e.select(e.User, () => ({ @@ -58,7 +58,7 @@ bench("select: nested", () => { const query = e.select(user, () => ({ id: true })); return {} as typeof query; -}).types([7911, "instantiations"]); +}).types([6420, "instantiations"]); bench("select: complex", () => { const query = e.select(e.Movie, () => ({ @@ -70,7 +70,7 @@ bench("select: complex", () => { }), })); return {} as typeof query; -}).types([6887, "instantiations"]); +}).types([6691, "instantiations"]); bench("select: with filter", () => { const query = e.select(e.Hero, (hero) => ({ @@ -82,7 +82,7 @@ bench("select: with filter", () => { filter_single: e.op(hero.name, "=", "Peter Parker"), })); return {} as typeof query; -}).types([7085, "instantiations"]); +}).types([6788, "instantiations"]); bench("select: with order", () => { const query = e.select(e.Hero, (hero) => ({ @@ -95,7 +95,7 @@ bench("select: with order", () => { filter_single: e.op(hero.name, "=", "Peter Parker"), })); return {} as typeof query; -}).types([7380, "instantiations"]); +}).types([7118, "instantiations"]); bench("select: with limit", () => { const query = e.select(e.Hero, (hero) => ({ @@ -108,7 +108,7 @@ bench("select: with limit", () => { filter_single: e.op(hero.name, "=", "Peter Parker"), })); return {} as typeof query; -}).types([7108, "instantiations"]); +}).types([6846, "instantiations"]); bench("select: with offset", () => { const query = e.select(e.Hero, (hero) => ({ @@ -121,7 +121,7 @@ bench("select: with offset", () => { filter_single: e.op(hero.name, "=", "Peter Parker"), })); return {} as typeof query; -}).types([7147, "instantiations"]); +}).types([6885, "instantiations"]); bench("params select", () => { const query = e.params({ name: e.str }, (params) => @@ -135,4 +135,4 @@ bench("params select", () => { })) ); return {} as typeof query; -}).types([14680, "instantiations"]); +}).types([13048, "instantiations"]); From 5848b86200b3e21623d7a7ba71d611bbed9a9899 Mon Sep 17 00:00:00 2001 From: Scott Trinh Date: Tue, 9 Jan 2024 16:19:23 -0500 Subject: [PATCH 06/10] Slightly cheaper "flatten" --- packages/driver/src/reflection/typeutil.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/driver/src/reflection/typeutil.ts b/packages/driver/src/reflection/typeutil.ts index 00df0a817..bd53e7b28 100644 --- a/packages/driver/src/reflection/typeutil.ts +++ b/packages/driver/src/reflection/typeutil.ts @@ -7,7 +7,7 @@ export namespace typeutil { export type depromisify = T extends Promise ? depromisify : T; export type identity = T; - export type flatten = identity<{ [k in keyof T]: T[k] }>; + export type flatten = { [k in keyof T]: T[k] } & unknown; export type tupleOf = [T, ...T[]] | []; export type writeable = { -readonly [P in keyof T]: T[P] }; From 30288ab1f388d255348634fcd7117da493a12e02 Mon Sep 17 00:00:00 2001 From: Scott Trinh Date: Tue, 9 Jan 2024 20:48:58 -0500 Subject: [PATCH 07/10] Some minor clean-up --- packages/generate/src/syntax/params.ts | 28 +++++++--------------- packages/generate/src/syntax/typesystem.ts | 6 +---- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/packages/generate/src/syntax/params.ts b/packages/generate/src/syntax/params.ts index 5e981ccc1..03b24c76b 100644 --- a/packages/generate/src/syntax/params.ts +++ b/packages/generate/src/syntax/params.ts @@ -16,6 +16,10 @@ import { runnableExpressionKinds } from "./query"; import { select } from "./select"; import { complexParamKinds } from "./__spec__"; +type Param = ParamType | $expr_OptionalParam; + +type ParamsRecord = Record; + export type $expr_OptionalParam = { __kind__: ExpressionKind.OptionalParam; __type__: Type; @@ -32,9 +36,7 @@ export function optional( export type QueryableWithParamsExpression< Set extends TypeSet = TypeSet, - Params extends { - [key: string]: ParamType | $expr_OptionalParam; - } = {} + Params extends ParamsRecord = Record > = Expression & { run( cxn: Executor, @@ -44,9 +46,7 @@ export type QueryableWithParamsExpression< }; export type $expr_WithParams< - Params extends { - [key: string]: ParamType | $expr_OptionalParam; - } = {}, + Params extends ParamsRecord = Record, Expr extends TypeSet = TypeSet > = QueryableWithParamsExpression< { @@ -59,11 +59,7 @@ export type $expr_WithParams< Params >; -type paramsToParamArgs< - Params extends { - [key: string]: ParamType | $expr_OptionalParam; - } -> = { +type paramsToParamArgs = { [key in keyof Params as Params[key] extends ParamType ? key : never]: Params[key] extends ParamType @@ -91,11 +87,7 @@ export type $expr_Param< __isComplex__: boolean; }>; -type paramsToParamExprs< - Params extends { - [key: string]: ParamType | $expr_OptionalParam; - } -> = { +type paramsToParamExprs = { [key in keyof Params]: Params[key] extends $expr_OptionalParam ? $expr_Param : Params[key] extends ParamType @@ -104,9 +96,7 @@ type paramsToParamExprs< }; export function params< - Params extends { - [key: string]: ParamType | $expr_OptionalParam; - } = {}, + Params extends ParamsRecord = Record, Expr extends Expression = Expression >( paramsDef: Params, diff --git a/packages/generate/src/syntax/typesystem.ts b/packages/generate/src/syntax/typesystem.ts index 9499b9d20..5ebcf9c37 100644 --- a/packages/generate/src/syntax/typesystem.ts +++ b/packages/generate/src/syntax/typesystem.ts @@ -47,11 +47,7 @@ export type scalarTypeWithConstructor< ExtraTsTypes = never > = S & { // tslint:disable-next-line - < - T extends S["__tstype__"] | ExtraTsTypes, - >( - val: T - ): $expr_Literal< + (val: T): $expr_Literal< Omit & { __tsconsttype__: T extends S["__tstype__"] ? T : S["__tstype__"]; } From 60100443562072325fb830a7f09a795ce6cf3ad2 Mon Sep 17 00:00:00 2001 From: Scott Trinh Date: Tue, 9 Jan 2024 20:49:08 -0500 Subject: [PATCH 08/10] Update bench snapshot --- integration-tests/lts/bench.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/integration-tests/lts/bench.ts b/integration-tests/lts/bench.ts index 77aa5bdec..075b85bb4 100644 --- a/integration-tests/lts/bench.ts +++ b/integration-tests/lts/bench.ts @@ -10,14 +10,14 @@ bench("scalar literal", () => { bench("array literal", () => { const lit = e.literal(e.array(e.str), ["abcd"]); return {} as typeof lit; -}).types([2454, "instantiations"]); +}).types([2407, "instantiations"]); bench("named tuple literal", () => { const lit = e.literal(e.tuple({ str: e.str }), { str: "asdf", }); return {} as typeof lit; -}).types([11654, "instantiations"]); +}).types([11597, "instantiations"]); bench("base type: array", () => { const baseType = e.array(e.str); @@ -42,14 +42,14 @@ bench("select: free object", () => { bench("select: id only", () => { const query = e.select(e.User, () => ({ id: true })); return {} as typeof query; -}).types([3910, "instantiations"]); +}).types([3699, "instantiations"]); bench("select: filtered", () => { const query = e.select(e.User, () => ({ filter_single: { id: e.uuid("123") }, })); return {} as typeof query; -}).types([5283, "instantiations"]); +}).types([5072, "instantiations"]); bench("select: nested", () => { const user = e.select(e.User, () => ({ @@ -58,7 +58,7 @@ bench("select: nested", () => { const query = e.select(user, () => ({ id: true })); return {} as typeof query; -}).types([6420, "instantiations"]); +}).types([6101, "instantiations"]); bench("select: complex", () => { const query = e.select(e.Movie, () => ({ @@ -70,7 +70,7 @@ bench("select: complex", () => { }), })); return {} as typeof query; -}).types([6691, "instantiations"]); +}).types([6358, "instantiations"]); bench("select: with filter", () => { const query = e.select(e.Hero, (hero) => ({ @@ -82,7 +82,7 @@ bench("select: with filter", () => { filter_single: e.op(hero.name, "=", "Peter Parker"), })); return {} as typeof query; -}).types([6788, "instantiations"]); +}).types([6349, "instantiations"]); bench("select: with order", () => { const query = e.select(e.Hero, (hero) => ({ @@ -95,7 +95,7 @@ bench("select: with order", () => { filter_single: e.op(hero.name, "=", "Peter Parker"), })); return {} as typeof query; -}).types([7118, "instantiations"]); +}).types([6679, "instantiations"]); bench("select: with limit", () => { const query = e.select(e.Hero, (hero) => ({ @@ -108,7 +108,7 @@ bench("select: with limit", () => { filter_single: e.op(hero.name, "=", "Peter Parker"), })); return {} as typeof query; -}).types([6846, "instantiations"]); +}).types([6407, "instantiations"]); bench("select: with offset", () => { const query = e.select(e.Hero, (hero) => ({ @@ -121,7 +121,7 @@ bench("select: with offset", () => { filter_single: e.op(hero.name, "=", "Peter Parker"), })); return {} as typeof query; -}).types([6885, "instantiations"]); +}).types([6446, "instantiations"]); bench("params select", () => { const query = e.params({ name: e.str }, (params) => @@ -135,4 +135,4 @@ bench("params select", () => { })) ); return {} as typeof query; -}).types([13048, "instantiations"]); +}).types([11920, "instantiations"]); From b18737e0fdb0085a23b87aaff5b187118d1a7dfe Mon Sep 17 00:00:00 2001 From: Scott Trinh Date: Wed, 10 Jan 2024 12:28:46 -0500 Subject: [PATCH 09/10] Name a union for minor gains --- integration-tests/lts/bench.ts | 18 +++++++-------- packages/generate/src/syntax/select.ts | 32 +++++++++++--------------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/integration-tests/lts/bench.ts b/integration-tests/lts/bench.ts index 075b85bb4..c77acc9eb 100644 --- a/integration-tests/lts/bench.ts +++ b/integration-tests/lts/bench.ts @@ -42,14 +42,14 @@ bench("select: free object", () => { bench("select: id only", () => { const query = e.select(e.User, () => ({ id: true })); return {} as typeof query; -}).types([3699, "instantiations"]); +}).types([3687, "instantiations"]); bench("select: filtered", () => { const query = e.select(e.User, () => ({ filter_single: { id: e.uuid("123") }, })); return {} as typeof query; -}).types([5072, "instantiations"]); +}).types([5081, "instantiations"]); bench("select: nested", () => { const user = e.select(e.User, () => ({ @@ -58,7 +58,7 @@ bench("select: nested", () => { const query = e.select(user, () => ({ id: true })); return {} as typeof query; -}).types([6101, "instantiations"]); +}).types([6099, "instantiations"]); bench("select: complex", () => { const query = e.select(e.Movie, () => ({ @@ -70,7 +70,7 @@ bench("select: complex", () => { }), })); return {} as typeof query; -}).types([6358, "instantiations"]); +}).types([6342, "instantiations"]); bench("select: with filter", () => { const query = e.select(e.Hero, (hero) => ({ @@ -82,7 +82,7 @@ bench("select: with filter", () => { filter_single: e.op(hero.name, "=", "Peter Parker"), })); return {} as typeof query; -}).types([6349, "instantiations"]); +}).types([6331, "instantiations"]); bench("select: with order", () => { const query = e.select(e.Hero, (hero) => ({ @@ -95,7 +95,7 @@ bench("select: with order", () => { filter_single: e.op(hero.name, "=", "Peter Parker"), })); return {} as typeof query; -}).types([6679, "instantiations"]); +}).types([6666, "instantiations"]); bench("select: with limit", () => { const query = e.select(e.Hero, (hero) => ({ @@ -108,7 +108,7 @@ bench("select: with limit", () => { filter_single: e.op(hero.name, "=", "Peter Parker"), })); return {} as typeof query; -}).types([6407, "instantiations"]); +}).types([6394, "instantiations"]); bench("select: with offset", () => { const query = e.select(e.Hero, (hero) => ({ @@ -121,7 +121,7 @@ bench("select: with offset", () => { filter_single: e.op(hero.name, "=", "Peter Parker"), })); return {} as typeof query; -}).types([6446, "instantiations"]); +}).types([6433, "instantiations"]); bench("params select", () => { const query = e.params({ name: e.str }, (params) => @@ -135,4 +135,4 @@ bench("params select", () => { })) ); return {} as typeof query; -}).types([11920, "instantiations"]); +}).types([11907, "instantiations"]); diff --git a/packages/generate/src/syntax/select.ts b/packages/generate/src/syntax/select.ts index 237c024e4..e5d1e3d29 100644 --- a/packages/generate/src/syntax/select.ts +++ b/packages/generate/src/syntax/select.ts @@ -750,15 +750,19 @@ type linkDescToShape = objectTypeToSelectShape< objectTypeToSelectShape> & SelectModifiers; -export type linkDescToSelectElement = +type linkDescToSelectElement = | boolean - // | pointerToCastableExpression | TypeSet, cardutil.assignable> | linkDescToShape | (( scope: $scopify & linkDescToLinkProps ) => linkDescToShape); +type propDescToSelectElement

= + | boolean + | TypeSet> + | $expr_PolyShapeElement; + // object types -> pointers // pointers -> links // links -> target object type @@ -766,23 +770,13 @@ export type linkDescToSelectElement = export type objectTypeToSelectShape< T extends ObjectType = ObjectType, Pointers extends ObjectTypePointers = T["__pointers__"] -> = - // ObjectType extends T - // ? {[k: string]: unknown} - // : - Partial<{ - [k in keyof Pointers]: Pointers[k] extends PropertyDesc - ? - | boolean - | TypeSet< - Pointers[k]["target"], - cardutil.assignable - > - | $expr_PolyShapeElement - : Pointers[k] extends LinkDesc - ? linkDescToSelectElement - : any; - }> & { [k: string]: unknown }; +> = Partial<{ + [k in keyof Pointers]: Pointers[k] extends PropertyDesc + ? propDescToSelectElement + : Pointers[k] extends LinkDesc + ? linkDescToSelectElement + : any; +}> & { [k: string]: unknown }; // incorporate __shape__ (computeds) on selection shapes // this works but a major rewrite of setToTsType is required From 2503362770a58030701bc936436d1598b84eb42a Mon Sep 17 00:00:00 2001 From: Scott Trinh Date: Wed, 10 Jan 2024 12:46:37 -0500 Subject: [PATCH 10/10] Extract conditional for another minor gain --- integration-tests/lts/bench.ts | 14 +++++++------- packages/generate/src/syntax/select.ts | 11 +++++------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/integration-tests/lts/bench.ts b/integration-tests/lts/bench.ts index c77acc9eb..256c11f2b 100644 --- a/integration-tests/lts/bench.ts +++ b/integration-tests/lts/bench.ts @@ -49,7 +49,7 @@ bench("select: filtered", () => { filter_single: { id: e.uuid("123") }, })); return {} as typeof query; -}).types([5081, "instantiations"]); +}).types([5019, "instantiations"]); bench("select: nested", () => { const user = e.select(e.User, () => ({ @@ -58,7 +58,7 @@ bench("select: nested", () => { const query = e.select(user, () => ({ id: true })); return {} as typeof query; -}).types([6099, "instantiations"]); +}).types([6037, "instantiations"]); bench("select: complex", () => { const query = e.select(e.Movie, () => ({ @@ -82,7 +82,7 @@ bench("select: with filter", () => { filter_single: e.op(hero.name, "=", "Peter Parker"), })); return {} as typeof query; -}).types([6331, "instantiations"]); +}).types([6289, "instantiations"]); bench("select: with order", () => { const query = e.select(e.Hero, (hero) => ({ @@ -95,7 +95,7 @@ bench("select: with order", () => { filter_single: e.op(hero.name, "=", "Peter Parker"), })); return {} as typeof query; -}).types([6666, "instantiations"]); +}).types([6624, "instantiations"]); bench("select: with limit", () => { const query = e.select(e.Hero, (hero) => ({ @@ -108,7 +108,7 @@ bench("select: with limit", () => { filter_single: e.op(hero.name, "=", "Peter Parker"), })); return {} as typeof query; -}).types([6394, "instantiations"]); +}).types([6352, "instantiations"]); bench("select: with offset", () => { const query = e.select(e.Hero, (hero) => ({ @@ -121,7 +121,7 @@ bench("select: with offset", () => { filter_single: e.op(hero.name, "=", "Peter Parker"), })); return {} as typeof query; -}).types([6433, "instantiations"]); +}).types([6391, "instantiations"]); bench("params select", () => { const query = e.params({ name: e.str }, (params) => @@ -135,4 +135,4 @@ bench("params select", () => { })) ); return {} as typeof query; -}).types([11907, "instantiations"]); +}).types([11865, "instantiations"]); diff --git a/packages/generate/src/syntax/select.ts b/packages/generate/src/syntax/select.ts index e5d1e3d29..5f6054dbf 100644 --- a/packages/generate/src/syntax/select.ts +++ b/packages/generate/src/syntax/select.ts @@ -96,6 +96,10 @@ export type SelectModifierNames = | "offset" | "limit"; +type filterSingle = T extends ObjectTypeSet + ? TypeSet, T["__cardinality__"]> + : orLiteralValue; + export type exclusivesToFilterSingle = ExclusiveTuple extends E ? never @@ -103,12 +107,7 @@ export type exclusivesToFilterSingle = ? never : { [j in keyof E]: { - [k in keyof E[j]]: E[j][k] extends ObjectTypeSet - ? TypeSet< - anonymizeObject, - E[j][k]["__cardinality__"] - > - : orLiteralValue; + [k in keyof E[j]]: filterSingle; }; }[number]; export type SelectModifiers = {