question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve require speed

See original GitHub issue

Issuehunt badges

I tested this by creating a new project and adding just time-require and chalk. I then created a simple time.js file with the following contents:

require('time-require')
require('chalk')

Results for Chalk 1.x (1.1.3 as of this posting):

Start time: (2017-07-22 16:50:03 UTC) [treshold=1%]
#  module                                                                time  %
1  pretty-ms (node_modules/pretty-ms/index.js)                            1ms  β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡ 11%
2  ansi-styles (node_modules/time-re...ules/ansi-styles/ansi-styles.js)   1ms  β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡ 11%
3  has-color (node_modules/has-color/index.js)                            1ms  β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡ 11%
4  chalk (node_modules/time-require/node_modules/chalk/index.js)          3ms  β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡ 33%
5  escape-string-regexp (node_modules/escape-string-regexp/index.js)      1ms  β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡ 11%
6  ansi-styles (node_modules/ansi-styles/index.js)                        1ms  β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡ 11%
7  has-ansi (node_modules/has-ansi/index.js)                              1ms  β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡ 11%
8  chalk (node_modules/chalk/index.js)                                    3ms  β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡ 33%
Total require(): 16
Total time: 9ms

Results for Chalk 2.x (2.0.1 as of this posting):

 #  module                                                                time  %
 1  text-table (node_modules/text-table/index.js)                          1ms  β–‡β–‡β–‡β–‡β–‡ 6%
 2  date-time (node_modules/date-time/index.js)                            1ms  β–‡β–‡β–‡β–‡β–‡ 6%
 3  parse-ms (node_modules/parse-ms/index.js)                              1ms  β–‡β–‡β–‡β–‡β–‡ 6%
 4  pretty-ms (node_modules/pretty-ms/index.js)                            1ms  β–‡β–‡β–‡β–‡β–‡ 6%
 5  ansi-styles (node_modules/time-re...ules/ansi-styles/ansi-styles.js)   1ms  β–‡β–‡β–‡β–‡β–‡ 6%
 6  has-color (node_modules/has-color/index.js)                            1ms  β–‡β–‡β–‡β–‡β–‡ 6%
 7  chalk (node_modules/time-require/node_modules/chalk/index.js)          2ms  β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡ 13%
 8  escape-string-regexp (node_modules/escape-string-regexp/index.js)      1ms  β–‡β–‡β–‡β–‡β–‡ 6%
 9  ./conversions (node_modules/color-convert/conversions.js)              2ms  β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡ 13%
10  color-convert (node_modules/color-convert/index.js)                    5ms  β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡ 31%
11  ansi-styles (node_modules/ansi-styles/index.js)                        6ms  β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡ 38%
12  os (os)                                                                1ms  β–‡β–‡β–‡β–‡β–‡ 6%
13  supports-color (node_modules/supports-color/index.js)                  1ms  β–‡β–‡β–‡β–‡β–‡ 6%
14  ./templates.js (node_modules/chalk/templates.js)                       1ms  β–‡β–‡β–‡β–‡β–‡ 6%
15  chalk (node_modules/chalk/index.js)                                   10ms  β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡ 63%
Total require(): 20
Total time: 16ms

I ran the tests several times locally and the results were all within 1ms each time.

For long running processes, the difference here is obviously negligible so I’ll understand if this gets closed out.

That being said, for CLI utils where boot time and responsiveness are far more important, it’s unfortunate that just using 2.x adds an additional 5ms+ on average that you can’t get back.


IssueHunt Summary

stroncium stroncium has been rewarded.

Backers (Total: $60.00)

Submitted pull Requests


Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Qix-commented, Jul 22, 2017

Not sure what you suggest we do about this.

The community complains about many tiny modules, and then gets mad when X module doesn’t have all of these features out of the box. So we’ve struck a somewhat bearable middleground by thinking really hard about every dependency we include.

0reactions
issuehunt-app[bot]commented, Sep 27, 2019

@sindresorhus has rewarded $54.00 to @stroncium. See it on IssueHunt

  • πŸ’° Total deposit: $60.00
  • πŸŽ‰ Repository reward(0%): $0.00
  • πŸ”§ Service fee(10%): $6.00
Read more comments on GitHub >

github_iconTop Results From Across the Web

9 Quick Ways to Improve Page Loading Speed - HubSpot Blog
Caching your web pages can help with lowering Time to First Byte (TTFB), by requiring the server to use fewer resources to load...
Read more >
How to evaluate and improve page speed - Moz
By optimizing your code (including removing spaces, commas, and other unnecessary characters), you can dramatically increase your page speed.
Read more >
THE 8 WAYS YOU CAN IMPROVE SPEED
THE 8 WAYS YOU CAN IMPROVE SPEED Β· 1. Improve Mobility Β· 2. Fix Asymmetries Β· 3. Build Core Stability Β· 4. Increase...
Read more >
Tips to improve website speed | How to speed up websites
Slow website speed and performance can have major negative effects. Learn how to boost site speed, and get started by performing a website...
Read more >
20 Ways to Speed Up Your Website and Improve Conversion ...
While all of these tips can help you improve your site speed, you don't need to do all of them today. In fact,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found