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

Using maps to save data in type-metadata.storage.ts would result in a giant performance boost on app startup #2206

Closed
1 task done
rezoled opened this issue May 31, 2022 · 5 comments
Labels

Comments

@rezoled
Copy link

rezoled commented May 31, 2022

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

In a large GQL application with 100s of schemas the bootstrap time for the Nest app is extremely slow.
This is caused mainly because of type-metadata.storage.ts which stores all the metadata in flat arrays.

On app startup, the class iterates over every GQL annotated class, and its fields, methods, their arguments and so on. Since all of the metadata is saved in arrays, this causes multiple iterations over each array with multiple levels of nesting.

Example: For a project with 100 GQL classes, with each 50 fields and methods (5,000 fields total), and 10 arguments per class (1,000 total), the recursion is as follows: 100 * 5,000 * 1,000 = 500,000,000

Describe the solution you'd like

Changing the data store models to Maps would result in O(1) access which would greatly optimize the startup time

Teachability, documentation, adoption, migration strategy

No response

What is the motivation / use case for changing the behavior?

Faster NestJS bootstrap time on large GQL projects

@kamilmysliwiec
Copy link
Member

Just to make sure that I'm following: are you suggesting replacing arrays with maps which contain arrays so in methods like these:

we could use, for example, interfaces[target] (or .get(target)) instead o using the find() method? If so, I'm all in for this change. The reason we've been using arrays is that we had to stay compatible with the type-graphql library (see comment at the top of the class declaration) which is no longer the case.

@rezoled
Copy link
Author

rezoled commented May 31, 2022

Exactly. I'd be happy to create a PR for that!

@kamilmysliwiec
Copy link
Member

Feel free to do so! 🙌

@rezoled
Copy link
Author

rezoled commented Jun 1, 2022

I created a PR with my public profile: #2212

@kamilmysliwiec
Copy link
Member

Let's track this here #2212

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

No branches or pull requests

2 participants