Switch to asynchronous methods
XhmikosR opened this issue · comments
fs
glob
What would probably speed things up a lot would be if this was async
Line 280 in 59d7c3e
We need to test this thoroughly (and on Windows) since we might hit a limit though.
@XhmikosR can you please check the builder in https://github.com/svg-sprite/svg-sprite/compare/async-bin branch
In my measurement the build time was slightly increased (about +0.1s)
Maybe it's the OS thing (I'm using Mac M1)
I haven't looked at the changes but here are the results from my dev VM (main vs your branch):
C:\Users\xmr\Desktop\bootstrap-icons>hyperfine "npm run icons-sprite"
Benchmark 1: npm run icons-sprite
Time (mean ± σ): 6.973 s ± 0.048 s [User: 0.004 s, System: 0.008 s]
Range (min … max): 6.902 s … 7.040 s 10 runs
C:\Users\xmr\Desktop\bootstrap-icons>npm i github:svg-sprite/svg-sprite#async-bin -D
changed 1 package, and audited 777 packages in 6s
130 packages are looking for funding
run `npm fund` for details
6 moderate severity vulnerabilities
Some issues need review, and may require choosing
a different dependency.
Run `npm audit` for details.
C:\Users\xmr\Desktop\bootstrap-icons>hyperfine "npm run icons-sprite"
Benchmark 1: npm run icons-sprite
Time (mean ± σ): 6.875 s ± 0.045 s [User: 0.001 s, System: 0.004 s]
Range (min … max): 6.779 s … 6.922 s 10 runs
BTW this will probably be better if all instances of sync methods are changed and probably if we used async syntax for better readability.
Another benchmark:
C:\Users\xmr\Desktop\bootstrap-icons>hyperfine "npm run icons-sprite"
Benchmark 1: npm run icons-sprite
Time (mean ± σ): 3.384 s ± 0.041 s [User: 0.003 s, System: 0.004 s]
Range (min … max): 3.332 s … 3.468 s 10 runs
C:\Users\xmr\Desktop\bootstrap-icons>npm i github:svg-sprite/svg-sprite#async-bin -D
changed 1 package, and audited 688 packages in 5s
161 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
C:\Users\xmr\Desktop\bootstrap-icons>hyperfine "npm run icons-sprite"
Benchmark 1: npm run icons-sprite
Time (mean ± σ): 3.263 s ± 0.022 s [User: 0.002 s, System: 0.004 s]
Range (min … max): 3.234 s … 3.300 s 10 runs
Definitely worth it assuming we use asynchronous methods everywhere.
If you have some time after #789, I'd really love to see a PR about this with all sync instances changed @Kreeg :)
Hey @XhmikosR.
I am struggling refactor this file further. The problem is that bin/svg-sprite.js
is a one big file with a lot of dependencies from fs
. So it's hard to switch to async in one leap. I'm suggesting to refactor this file first. At least there is to big parts that can be isolated. It is a parsing and making a config and run bundling.
If you think it will help sure.
Generally, requiring more files increases the load time. Which is something that will be fixed if we switch to ESM at some point, but that's for another time :)
My main issue with CLI is the lack of tests so it's hard to make any changes. And we already have a couple of regressions which are blocking us from releasing v3.0.0.