Skip to content

Commit 2030df1

Browse files
committed
don't disable the gc with multiple entry points
1 parent b9e9513 commit 2030df1

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

cmd/esbuild/main.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,20 +282,23 @@ func main() {
282282
exitCode = cli.Run(osArgs)
283283
}
284284
} else {
285-
// Don't disable the GC if this is a long-running process
286285
isServeOrWatch := false
286+
nonFlagCount := 0
287287
for _, arg := range osArgs {
288-
if arg == "--serve" || arg == "--watch" || strings.HasPrefix(arg, "--serve=") {
288+
if !strings.HasPrefix(arg, "-") {
289+
nonFlagCount++
290+
} else if arg == "--serve" || arg == "--watch" || strings.HasPrefix(arg, "--serve=") {
289291
isServeOrWatch = true
290-
break
291292
}
292293
}
293294

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

0 commit comments

Comments
 (0)