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

Query Types Performance #1

Open
kauderk opened this issue Apr 20, 2023 · 0 comments
Open

Query Types Performance #1

kauderk opened this issue Apr 20, 2023 · 0 comments

Comments

@kauderk
Copy link
Owner

kauderk commented Apr 20, 2023

Excalidraw Link Excalidraw Link


Premise:

I need help optimizing the performance of my Mapped Types..

Case:

On 972cb8fa
TThe /query endpoint is designed to accept a schema and return the shape either flattened or as requested, handling optional, partial, or undefined cases.

Problem:

While editing, the performance of inferred types on the IDE is slow. It won't deter anyone from using the program, but we're accustomed to fast iterations, and even a little bit slower is too much. There are too many mapped types.

DX won't hurt anybody right?

Escape Patch

There is a tsAny: boolean option on every Query to bypass typechecking. With over 4000+ base queries and their combinations, it is important to recover performance wherever possible. One could enable this option when the fetch logic is complete.


This could be so much more simple, hell even one single Mapped type...

STEPS

FlattenAgainstSchema
Walks down the schema until it finds a non-object, while doing so
saves the last key onto a stack (string).
It will resolve a mapped type of {[nested.optional.properties.with.the.response]: value}

BrachOut
If isVerbose continue executing, else shrink the nested paths <- right-to-left

PathsToOutput
Takes a Record (aka Path), and Value>
Searches the LastKey recursively on the Path to reach the last property.name (aka Leaf)
Then acts on objects and arrays:
for objects -> {parent:{property: value}} | parent.property
for arrays -> {parent: {[index]: value}} | parent.index.property
For each, carries variables for the OriginalPath, LeafToValue, isVerboseOrFlatten
If it is an optional/NullCoalescing path, shift the uncertainty to the parent,
    meaning grab the "?" and put it higher on the Path
If it isVerbose
    infer the BranchPath and append the Leaf, else it's just the leaf.path

Assemble
Walks down each branch and creates nested objects by pulling keys from the branch
It will return a mapped type of {[branch.to.value]: ReconstructFromBranch<branch.to.value>}

Merge
It gets the union of values of the ReconstructedFromBranch Map type
then it intersect all branches into a single Tree/Schema

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant