Skip to content

Commit

Permalink
fix #2661: avoid extra rebuilds with debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Nov 9, 2022
1 parent ba47710 commit c6e880a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,13 @@
# Changelog

## Unreleased

* Avoid unnecessary watch mode rebuilds when debug logging is enabled ([#2661](https://github.com/evanw/esbuild/issues/2661))

When debug-level logs are enabled (such as with `--log-level=debug`), esbuild's path resolution subsystem generates debug log messages that say something like "Read 20 entries for directory /home/user" to help you debug what esbuild's path resolution is doing. This caused esbuild's watch mode subsystem to add a dependency on the full list of entries in that directory since if that changes, the generated log message would also have to be updated. However, meant that on systems where a parent directory undergoes constant directory entry churn, esbuild's watch mode would continue to rebuild if `--log-level=debug` was passed.

With this release, these debug log messages are now generated by "peeking" at the file system state while bypassing esbuild's watch mode dependency tracking. So now watch mode doesn't consider the count of directory entries in these debug log messages to be a part of the build that needs to be kept up to date when the file system state changes.

## 0.15.13

* Add support for the TypeScript 4.9 `satisfies` operator ([#2509](https://github.com/evanw/esbuild/pull/2509))
Expand Down
11 changes: 11 additions & 0 deletions internal/fs/fs.go
Expand Up @@ -112,6 +112,17 @@ func (entries DirEntries) Get(query string) (*Entry, *DifferentCase) {
return nil, nil
}

// This function lets you "peek" at the number of entries without watch mode
// considering the number of entries as having been observed. This is used when
// generating debug log messages to log the number of entries without causing
// watch mode to rebuild when the number of entries has been changed.
func (entries DirEntries) PeekEntryCount() int {
if entries.data != nil {
return len(entries.data)
}
return 0
}

func (entries DirEntries) SortedKeys() (keys []string) {
if entries.data != nil {
keys = make([]string, 0, len(entries.data))
Expand Down
2 changes: 1 addition & 1 deletion internal/resolver/resolver.go
Expand Up @@ -915,7 +915,7 @@ func (r resolverQuery) dirInfoCached(path string) *dirInfo {
if cached == nil {
r.debugLogs.addNote(fmt.Sprintf("Failed to read directory %q", path))
} else {
count := len(cached.entries.SortedKeys())
count := cached.entries.PeekEntryCount()
entries := "entries"
if count == 1 {
entries = "entry"
Expand Down

0 comments on commit c6e880a

Please sign in to comment.