fix(perf): lazy load workspace dependency#7352
fix(perf): lazy load workspace dependency#7352wraithgar merged 2 commits intonpm:latestfrom H4ad:perf/lazy-load-workspaces
Conversation
|
Test failures are gonna be real educational on this one, I can just feel it. |
|
I tried to read why the tests are falling but I have no clue, I tried to roll back and looks like the |
|
Oh, I think I understand the issue, the The solution is:
|
@isaacs maintains both so maybe they know off the top of their head? |
|
I think 6ms may not be worth our trouble to have to start setting up a Jenga tower of correct require orders here. We may have to back off on that lazy loading. |
|
I have no idea. If you have a repro that shows the two conflicting in some way, I can take a look, but path-scurry doesn't even do much with the fs, just reads from it. Maybe gfs is breaking some function signature path scurry is expecting? 🤷 |
We already have this jenga tower, if you move @isaacs Just clone this repo and checkout to this branch, and then run |
|
This repo no longer has that error. It may not be worth your time if it's not something you know off the top of your head @isaacs. Unsubscribe and move on, thanks for your quick response. |
|
I didn't fix the issue with @isaacs if you want to understand more, you can use this branch: https://github.com/H4ad/cli/tree/issue-with-graceful |
|
The tests are ok, just the coverage is not enough, right? |
|
@wraithgar On Node 18.x, we have a race condition while deleting the logs. Since we did not wait to delete the logs, the If I replace both versions to use the What do you want to do in this case? |
|
I'm digging into this today but I do seem to remember this comment at the end of // Return the result so it can be awaited in tests
return this.#cleanLogs() |
|
It's entirely possible we have bugs here. I do know that sometimes my npm logs dir is filled with old logs that never get cleaned up, and haven't taken the time to triage that. |
What I'm seeing is unrelated, we're deleting the newest logs not the oldest ones. That will fix the bug I'm seeing. |
The algorithm deletes the oldest ones, they are automatically ordered when they come from the Also, the tests are passing, so I guess the deleting is right. To fix, should I include |
|
The original idea behind this method not containing any synchronous code is that it is all run as a best effort and we don't want to block anything. So we do So I do think we should keep all the log cleaning code using |
They are not in osx. Looks like we have some cross-platform bugs. That's outside the scope of this PR but at least now I know exactly where that bug I was seeing lies.
Yes this post is 100% my understanding of the situation. |
|
Maybe I'm missing something, but the |
|
We do not wait in these lines: Lines 260 to 266 in 70497cb I suppose it was intentional
I think a simple sort should fix these issues. |
glob used to sort, and it doesn't anymore. As part of our update to the latest version we manually sorted its results. Looks like we missed this one. ETA: example of us preserving glob@8 behavior cli/lib/commands/help-search.js Lines 20 to 22 in 70497cb |
Yes, we do not await any of this from npm itself. Our tests however are awaiting the |
|
The The Which as you can see is wrong, it doubles the filename for some reason. Node 20 doesn't do this. There is either a bug or a breaking change in This is a readdir response in node18 This is in node 20 Here's an isolated example of the difference: ~/D/n/s/readdir $ nvm use v20
Now using node v20.10.0 (npm v10.5.1)
~/D/n/s/readdir $ node -e "require('fs/promises').readdir('.', { withFileTypes: true, encoding: 'utf-8', }).then(console.log)"
[ Dirent { name: 'test.js', path: '.', [Symbol(type)]: 1 } ]
~/D/n/s/readdir $ nvm use v18
Now using node v18.20.1 (npm v10.5.1)
~/D/n/s/readdir $ node -e "require('fs/promises').readdir('.', { withFileTypes: true, encoding: 'utf-8', }).then(console.log)"
[
Dirent {
name: 'test.js',
parentPath: '.',
path: 'test.js',
[Symbol(type)]: 1
}
] |
|
Now using node v18.20.1 (npm v10.5.1)
~/D/n/s/readdir $ node -e "require('fs/promises').readdir('.', { encoding: 'utf-8', }).then(console.log)"
[ 'test.js' ]
~/D/n/s/readdir $ nvm use v20
Now using node v20.10.0 (npm v10.5.1)
~/D/n/s/readdir $ node -e "require('fs/promises').readdir('.', { encoding: 'utf-8', }).then(console.log)"
[ 'test.js' ] |
|
This gets us green in node 18 and 20. If you can't get to this before tomorrow I'll make a new PR w/ this included so it can go out w/ tomorrow's release ~/D/n/c/b/main (perf/lazy-load-workspaces|✚1) $ git diff
diff --git a/lib/utils/log-file.js b/lib/utils/log-file.js
index 62b191a0d..1a46b7da0 100644
--- a/lib/utils/log-file.js
+++ b/lib/utils/log-file.js
@@ -204,11 +204,13 @@ class LogFiles {
// counter suffix
.replace('-.log', '')
- const files = await fs.readdir(
+ let files = await fs.readdir(
dirname(logPath), {
withFileTypes: true,
encoding: 'utf-8',
})
+ files = files.sort((a, b) => basename(a.name).localeCompare(basename(b.name), 'en'))
+
const logFiles = []
for (const file of files) {
@@ -217,7 +219,7 @@ class LogFiles {
}
const genericFileName = file.name.replace(/\d/g, 'd')
- const filePath = join(file.path, file.name)
+ const filePath = join(dirname(logPath), basename(file.name)) |
|
Thanks for the detailed investigation, as soon I get more time, I will try to investigate to see if this was an expected behavior on Node 18 or if it's a bug. |
|
Failures are in windows shims tests, unrelated to this PR. Those are known flaky tests. |
|
PHEW, we got there in the end. Thanks for sticking it through @H4ad. |
|
haha no worries, happy to help! I also created an issue on node, this is actually a bug: nodejs/node#52441 |
Lazy loading
workspacesandglobdependencies, will avoid loading the dependency when running inside a repo that is not a workspace and also will not loadglobwhen is not needed.Before:
After: