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

Optimize types to decrease building time #25

Merged
merged 1 commit into from
Jan 7, 2025

Conversation

coolassassin
Copy link
Contributor

@coolassassin coolassassin commented Dec 24, 2024

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 and injectable 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:

  • before:
    image
  • after:
    image

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!

@bukhtiyarov-a-v
Copy link

bukhtiyarov-a-v commented Dec 24, 2024

optimize types to increase building time

I think, that's to decrease, actually 😄
Looking forward to that improvement! 👍

@coolassassin coolassassin changed the title Optimize types to increase building time Optimize types to decrease building time Dec 24, 2024
@raveclassic
Copy link
Owner

Wow, the results look really impressive! I'll be able to get to my laptop after 05.01 and release the new version. Thanks!

@coolassassin
Copy link
Contributor Author

@raveclassic just a friendly reminder about this PR 😊

It can also be useful for your package to fill some fields in your package.json, because it is hard to find your package in NPM.
I mean fields like:

  • description
  • author
  • license
  • repository
  • homepage
  • bugs
  • keywords

It also can make your package way more popular 👍

@raveclassic raveclassic self-requested a review January 7, 2025 12:40
@raveclassic raveclassic merged commit b21d193 into raveclassic:main Jan 7, 2025
1 check passed
raveclassic pushed a commit that referenced this pull request Jan 7, 2025
@raveclassic
Copy link
Owner

@coolassassin @bukhtiyarov-a-v I've just released 1.0.0-rc.0 - thanks for the contribution!

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

Successfully merging this pull request may close these issues.

3 participants