diff --git a/cmd/esbuild/main.go b/cmd/esbuild/main.go index 76712ccc8f6..67744f00bca 100644 --- a/cmd/esbuild/main.go +++ b/cmd/esbuild/main.go @@ -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.