Skip to content

Commit

Permalink
don't disable the gc with multiple entry points
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Dec 4, 2022
1 parent b9e9513 commit 2030df1
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions cmd/esbuild/main.go
Expand Up @@ -282,20 +282,23 @@ func main() {
exitCode = cli.Run(osArgs)
}
} else {
// Don't disable the GC if this is a long-running process
isServeOrWatch := false
nonFlagCount := 0
for _, arg := range osArgs {
if arg == "--serve" || arg == "--watch" || strings.HasPrefix(arg, "--serve=") {
if !strings.HasPrefix(arg, "-") {
nonFlagCount++
} else if arg == "--serve" || arg == "--watch" || strings.HasPrefix(arg, "--serve=") {
isServeOrWatch = true
break
}
}

if !isServeOrWatch {
// Disable the GC since we're just going to allocate a bunch of memory
// and then exit anyway. This speedup is not insignificant. Make sure to
// only do this here once we know that we're not going to be a long-lived
// process though.
if !isServeOrWatch && nonFlagCount <= 1 {
// If this is not a long-running process and there is at most a single
// entry point, then disable the GC since we're just going to allocate
// a bunch of memory and then exit anyway. This speedup is not
// insignificant. We don't do this when there are multiple entry points
// since otherwise esbuild could unnecessarily use much more memory
// than it might otherwise need to process many entry points.
debug.SetGCPercent(-1)
} else if !isStdinTTY && !isWatchForever {
// If stdin isn't a TTY, watch stdin and abort in case it is closed.
Expand Down

0 comments on commit 2030df1

Please sign in to comment.