Optimize types to decrease building time #25
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello @raveclassic !
We have been using @injectable-ts in our project for a long time and we have a deep injectable structure.
And last time we have more and more issues with developer experience.
Freezes, long build time, etc.
I have investigated this issue for a long time to find out the root of the issue. We already thought to avoid deep dependencies or even remove this library from our project, but I finally have found the problem
The main issue is dynamic object types included in
token
andinjectable
functions.More than that this approach creates huge dependencies object with no cache from typescript.
As a result in some cases, we have generated d.ts files for 20k+ rows and huge freezes in IDE(Webstrom, VSCode, Cursor) and in CI on building steps(more than 1 hour for our mono repository to build all packages)
In this pull request, you can see that I have extracted some types to make the result type of compilation as short as possible.
The file that had 21419 rows became a file with 185 rows but with the same structure.
But the main issue is performance and I can show you significant results on one of the slowest projects (build time) in the repository:
It is 44 times faster than before. I have checked this many times with no cache and the result is always better.
I hope you will enjoy this solution and include this in your next release!
Thank you!