-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
ReadDirectory searches deep in your filesystem #254
Comments
This is a consequence of some performance optimizations I've added. Unfortunately node's module resolution algorithm is quite heavy in terms of file system calls because it requires many "does this file/directory exist" checks to find each path (which was kind of a mistake but we're stuck with it). This is even worse for bundlers than it is for node because while node just checks a few things ( Querying for each potential file location using And the reason esbuild reads all the way up to the root is that each cached directory info query depends on its parent directory. This is because esbuild does path resolution in parallel and it was convenient for having access to the info of a directory to also implicitly grant you access to the info of the parent directories without further locking and coordination overhead. In practice this was very little overhead because the parent directories of the project you're in are only read once and then cached for all queries. It's possible that all of this could be improved. It would be good to know if people are encountering any performance issues with this approach. The approach was taken because it was a big performance boost, so any change to this approach will need to be carefully analyzed to avoid causing performance regressions. |
Gotcha. Thanks for sharing the details! For some reason I thought Node fixed this, but I just double-checked and it looks like this is following Node's require algorithm, "if you don't find it in node_modules, look in the parent". I get it now, you're doing this resolution eagerly to avoid needing to do it every time.
Bummer! |
Problem
I noticed that
func (fs *realFS) ReadDirectory
looks quite deep into the file system. I see this as a problem in two ways:How to Reproduce
1. If you do add
fmt.Println(entryPath)
after entryPath:esbuild/internal/fs/fs.go
Lines 224 to 225 in 5c6b3ab
2. Create an
index.js
:3.
go install ./cmd/esbuild
4. Run
esbuild index.js
.You should see something like:
The text was updated successfully, but these errors were encountered: