-
Notifications
You must be signed in to change notification settings - Fork 13
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
fix: cache local environment values #120
Conversation
Another option is to copy the logic from yarn which also fixed this issue by looking into the |
Is getReport() called once during npm install or multiple times? |
Currently multiple times because it's called at every checkPlatform, which is done in a loop once per installed package during npm install, which is what this PR is attempting to fix. I have also submitted a fix to the node js implementation so that get Report doesn't take long times if excludeNetwork is true, at which point we don't need to cache getReport early, just caching it after the first call will be enough |
Many projects have more than 100 dependencies. In my opinion it makes sense to limit the getReport call to one time as it performs other tasks as well and the system properties wont chance during installation. |
@reggi Any chance you can review and merge this quickly as this issue is serious (can completely hog CI servers) and prevents |
I don't think the approach of assigning our own attributes to |
@wraithgar I added the ldd file check with tests and use a mocked file to bypass the cache and avoid assigning to process.report |
We're VERY close imo. Just gotta get the coverage fixed and we can ship this. I'm holding off on the next npm release till this lands because I think it should be pretty soon. |
The testing setup is a little hard to follow with the extra callbacks but I don't think it's a blocker. We can refactor that later. pinging @H4ad in case they had any input before we land this (hopefully today) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't approve but LGTM!
🤖 I have created a release *beep* *boop* --- ## [7.1.1](v7.1.0...v7.1.1) (2024-11-21) ### Bug Fixes * [`acf64a7`](acf64a7) [#120](#120) cache local environment values (#120) (@Tofandel) ### Chores * [`fca8f29`](fca8f29) [#119](#119) bump @npmcli/template-oss from 4.23.3 to 4.23.4 (#119) (@dependabot[bot], @npm-cli-bot) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Yes this is a bit dirty because the report is now generated once at the beginning of a command which could be considered a side effect (but normally treeshaking will only include it only if needed), but the whole process.report is a weirdly built API meant for debugging and not really meant to be used in a normal program
But somehow when the call is done in the beginning of the process, this call is very fast, but when it's called after having run a http request (as is currently the case, a single call takes a lot more time to complete, it takes 40s or more on my system when called at the end of npm upgrade) but only a few milliseconds when called at the beginning (this is why it's best to run it outside the function at the beginning of the process as a side effect instead of calling getReport on demand and cache the result)
Here is a log of console.time('report') and console.timeEnd('report') before and after the getReport call
when run in the end of the upgrade command:
⠼report: 3:10.573 (m:ss.mmm)
when run in the beginning of the process at the top level
report: 1.943ms
This fixes npm hanging npm/cli#4028, npm/cli#7814, npm/cli#7868