You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[perf] lib/compiler.js makes too many stat() calls #167
Profiling loopback-sample-app start-up time, from the ~6500 stat() system calls, about 2000 originate from fixFileExtension() and to a lesser extent tryResolveAppPath() in lib/compiler.js (the fs.existsSync() call - why are you using that?)
Related, I managed to bring down the number of calls from node.js core to ~2800 from ~4700 in nodejs/node#4575 by caching more aggressively. Perhaps a similar strategy is possible in lib/compiler.js?
--perf_basic_prof exists in node v4.x or v5.x and records JS stack frames, making the profiler's output a lot more useful.
You may have to remount /sys/kernel/debug and /sys/kernel/debug/tracing with mount -o remount,mode=755. Add -m64 if perf complains about not having permission to mmap memory.
If you just want to count the number of system calls:
@ritch I would like to bump up the priority of this issue and fix the performance in both loopback-boot@2 (which is used by current loopback-workspace version) and loopback-boot@3 (that will be eventually used instead).
Whenever we are trying to resolve an extension-less name to a real require-able file name, we read the content of the directory. I don't have profiling data to prove this adds significant overhead, it's just my guess.
Other places calling tryReadDir may be worth optimising too.
I created a simple breakdown of how long the different parts of loopback-workspace's server/server.js take to finish (Node v6.9.4 using console.time/console.timeEnd functions):
This break-down shows that the execution of loopback-boot takes only about ~10% of the startup time. Most of the time is spent loading (require()ing) the following two modules: strong-globalize and loopback.
Given this data, I think optimising filesystem access in loopback-boot is not worth our effort right now, because the effect on real applications will be minimal.
@bnoordhuis thoughts? Can you advise how to analyse which (sub)dependencies of loopback and strong-globalize are contributing most to the unusually high load time?
BTW when I had loopback-boot npm-linked into loopback-workspace, the load time went from ~38ms to ~429ms. I think this suggests loopback-boot is sharing quite few dependencies with loopback (npm@3 is using flat layout in node_modules, when loopback-boot is installed locally then it can use the same require()d instances of dependency modules than loopback does).
Activity
bnoordhuis commentedon Jan 8, 2016
If you want to see for yourself:
--perf_basic_profexists in node v4.x or v5.x and records JS stack frames, making the profiler's output a lot more useful.You may have to remount
/sys/kernel/debugand/sys/kernel/debug/tracingwithmount -o remount,mode=755. Add-m64if perf complains about not having permission to mmap memory.If you just want to count the number of system calls:
bajtos commentedon Jan 4, 2017
This problem is slowing down
yo loopback(and the upcominglb) command, asloobpack-workspacetakes about a second to load. The problem gets even worse inlbtests (https://github.com/strongloop/loopback-cli, see https://github.com/strongloop-internal/scrum-loopback/issues/1028), where each test invokinglbin a subprocess is paying this cost and the test suite takes quite long to complete.@ritch I would like to bump up the priority of this issue and fix the performance in both
loopback-boot@2(which is used by current loopback-workspace version) andloopback-boot@3(that will be eventually used instead).bnoordhuis commentedon Jan 6, 2017
I can spend some time on this in the week of January 16. LMK if I should.
bajtos commentedon Jan 6, 2017
@bnoordhuis thank you for the offer, any help is welcome!
Specifically in loopback-boot, I think there is another place where we are repeating the same filesystem query - see
loopback-boot/lib/compiler.js
Lines 685 to 694 in 9cb3d06
Whenever we are trying to resolve an extension-less name to a real require-able file name, we read the content of the directory. I don't have profiling data to prove this adds significant overhead, it's just my guess.
Other places calling
tryReadDirmay be worth optimising too.bajtos commentedon Jan 25, 2017
I created a simple breakdown of how long the different parts of
loopback-workspace'sserver/server.jstake to finish (Node v6.9.4 usingconsole.time/console.timeEndfunctions):This break-down shows that the execution of loopback-boot takes only about ~10% of the startup time. Most of the time is spent loading (
require()ing) the following two modules:strong-globalizeandloopback.Given this data, I think optimising filesystem access in loopback-boot is not worth our effort right now, because the effect on real applications will be minimal.
@bnoordhuis thoughts? Can you advise how to analyse which (sub)dependencies of loopback and strong-globalize are contributing most to the unusually high load time?
BTW when I had loopback-boot npm-linked into loopback-workspace, the load time went from ~38ms to ~429ms. I think this suggests loopback-boot is sharing quite few dependencies with loopback (npm@3 is using flat layout in node_modules, when loopback-boot is installed locally then it can use the same
require()d instances of dependency modules than loopback does).bnoordhuis commentedon Jan 25, 2017
I'll take a look, I have time today. What loopback-boot version did you benchmark? Master?
bajtos commentedon Jan 25, 2017
loopback-boot branch
2.x, loopback-workspace branchmaster.bajtos commentedon Nov 2, 2018
Since there was no activity here for almost two years, and our focus is on LB4+ now, I am closing this issue as stale/abandoned.