Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move expensive type expressions to generic #830

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions integration-tests/lts/bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ bench("select: free object", () => {
bench("select: id only", () => {
const query = e.select(e.User, () => ({ id: true }));
return {} as typeof query;
}).types([3642, "instantiations"]);
}).types([3895, "instantiations"]);

bench("select: filtered", () => {
const query = e.select(e.User, () => ({
filter_single: { id: e.uuid("123") },
}));
return {} as typeof query;
}).types([5384, "instantiations"]);
}).types([5386, "instantiations"]);

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

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

bench("select: complex", () => {
const query = e.select(e.Movie, () => ({
Expand All @@ -43,7 +43,7 @@ bench("select: complex", () => {
}),
}));
return {} as typeof query;
}).types([6339, "instantiations"]);
}).types([6556, "instantiations"]);

bench("select: with filter", () => {
const query = e.select(e.Hero, (hero) => ({
Expand All @@ -55,7 +55,7 @@ bench("select: with filter", () => {
filter_single: e.op(hero.name, "=", "Peter Parker"),
}));
return {} as typeof query;
}).types([98669, "instantiations"]);
}).types([6690, "instantiations"]);

bench("select: with order", () => {
const query = e.select(e.Hero, (hero) => ({
Expand All @@ -68,7 +68,7 @@ bench("select: with order", () => {
filter_single: e.op(hero.name, "=", "Peter Parker"),
}));
return {} as typeof query;
}).types([98963, "instantiations"]);
}).types([6985, "instantiations"]);

bench("select: with limit", () => {
const query = e.select(e.Hero, (hero) => ({
Expand All @@ -81,7 +81,7 @@ bench("select: with limit", () => {
filter_single: e.op(hero.name, "=", "Peter Parker"),
}));
return {} as typeof query;
}).types([98694, "instantiations"]);
}).types([6713, "instantiations"]);

bench("select: with offset", () => {
const query = e.select(e.Hero, (hero) => ({
Expand All @@ -94,5 +94,4 @@ bench("select: with offset", () => {
filter_single: e.op(hero.name, "=", "Peter Parker"),
}));
return {} as typeof query;
}).types([98730, "instantiations"]);

}).types([6752, "instantiations"]);
42 changes: 20 additions & 22 deletions packages/generate/src/syntax/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,18 +848,17 @@ export const $existingScopes = new Set<

function $shape<
Expr extends ObjectTypeExpression,
Shape extends objectTypeToSelectShape<Expr["__element__"]> &
SelectModifiers<Expr["__element__"]> // <Expr["__element__"]>
Element extends Expr["__element__"],
Shape extends objectTypeToSelectShape<Element> & SelectModifiers<Element>,
Scope extends $scopify<Element> &
$linkPropify<{
[k in keyof Expr]: k extends "__cardinality__"
? Cardinality.One
: Expr[k];
}>
>(
expr: Expr,
_shape: (
scope: $scopify<Expr["__element__"]> &
$linkPropify<{
[k in keyof Expr]: k extends "__cardinality__"
? Cardinality.One
: Expr[k];
}>
) => Readonly<Shape>
_shape: (scope: Scope) => Readonly<Shape>
): (scope: unknown) => Readonly<Shape>;
function $shape(_a: unknown, b: (...args: any) => any) {
return b;
Expand All @@ -881,23 +880,22 @@ export function select<Expr extends TypeSet>(
): $expr_Select<stripSet<Expr>>;
export function select<
Expr extends ObjectTypeExpression,
Shape extends objectTypeToSelectShape<Expr["__element__"]> &
SelectModifiers<Expr["__element__"]>,
Element extends Expr["__element__"],
Scope extends $scopify<Element> &
$linkPropify<{
[k in keyof Expr]: k extends "__cardinality__"
? Cardinality.One
: Expr[k];
}>,
Shape extends objectTypeToSelectShape<Element> & SelectModifiers<Element>,
Modifiers extends UnknownSelectModifiers = Pick<Shape, SelectModifierNames>
>(
expr: Expr,
shape: (
scope: $scopify<Expr["__element__"]> &
$linkPropify<{
[k in keyof Expr]: k extends "__cardinality__"
? Cardinality.One
: Expr[k];
}>
) => Readonly<Shape>
shape: (scope: Scope) => Readonly<Shape>
): $expr_Select<{
__element__: ObjectType<
`${Expr["__element__"]["__name__"]}`, // _shape
Expr["__element__"]["__pointers__"],
`${Element["__name__"]}`, // _shape
Element["__pointers__"],
Omit<normaliseShape<Shape>, SelectModifierNames>
>;
__cardinality__: ComputeSelectCardinality<Expr, Modifiers>;
Expand Down
Loading