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

⚡ Use dynamic imports instead of static imports #1126

Merged
merged 1 commit into from
Jun 19, 2023

Conversation

segersniels
Copy link
Collaborator

@segersniels segersniels commented Jun 16, 2023

Description

This PR updates the imports from static imports to dynamic imports which should result in some easy speed improvements.

Changed

  • Improved startup speed by utilising dynamic imports for each command only when they are needed. This improves the initial startup time because it doesn't have to load in all the other commands that are unused.

Issues

@codecov
Copy link

codecov bot commented Jun 16, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (cdfc070) 91.90% compared to head (4cd4c45) 91.90%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1126   +/-   ##
=======================================
  Coverage   91.90%   91.90%           
=======================================
  Files          28       28           
  Lines         284      284           
  Branches       69       69           
=======================================
  Hits          261      261           
  Misses         22       22           
  Partials        1        1           

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@segersniels
Copy link
Collaborator Author

segersniels commented Jun 16, 2023

gitmoji  0.42s user 0.07s system 112% cpu 0.431 total
node lib/cli.js  0.16s user 0.03s system 78% cpu 0.253 total
gitmoji search bug linter  0.45s user 0.11s system 80% cpu 0.695 total
node lib/cli.js search bug linter  0.32s user 0.05s system 91% cpu 0.399 total
gitmoji list  0.44s user 0.07s system 88% cpu 0.580 total
node lib/cli.js list  0.31s user 0.05s system 92% cpu 0.383 total

@@ -59,14 +58,20 @@ const cli = meow(
)

export const options = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! It improves startup time, but I'm wondering how much it affects the overall execution time of the command? So we can understand the trade-offs of the solution 👀

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't affect anything. It defers loading to when it's needed instead of pulling everything in memory from the get go. Code execution following the dynamic import proceeds like usual. It just gets to executing a lot faster since it doesn't have to load in all the other commands and their dependencies.

Only downside of dynamic importing AFAIK is the fact that tree shaking won't be available for the commands and their dependencies.

@carloscuesta carloscuesta merged commit db025ba into master Jun 19, 2023
@carloscuesta carloscuesta deleted the optim/async-import branch June 19, 2023 08:36
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants