Skip to content

Commit eb3dbac

Browse files
authored
Merge pull request kubernetes#93572 from liggitt/parallel-typecheck
Limit typecheck parallelism by default
2 parents 72a62bc + 7cbdb4f commit eb3dbac

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

test/typecheck/main.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ var (
3838
platforms = flag.String("platform", "", "comma-separated list of platforms to typecheck")
3939
timings = flag.Bool("time", false, "output times taken for each phase")
4040
defuses = flag.Bool("defuse", false, "output defs/uses")
41-
serial = flag.Bool("serial", false, "don't type check platforms in parallel")
41+
serial = flag.Bool("serial", false, "don't type check platforms in parallel (equivalent to --parallel=1)")
42+
parallel = flag.Int("parallel", 4, "limits how many platforms can be checked in parallel. 0 means no limit.")
4243
skipTest = flag.Bool("skip-test", false, "don't type check test code")
4344
tags = flag.String("tags", "", "comma-separated list of build tags to apply in addition to go's defaults")
4445
ignoreDirs = flag.String("ignore-dirs", "", "comma-separated list of directories to ignore in addition to the default hardcoded list including staging, vendor, and hidden dirs")
@@ -273,9 +274,24 @@ func main() {
273274
var wg sync.WaitGroup
274275
var failMu sync.Mutex
275276
failed := false
277+
278+
if *serial {
279+
*parallel = 1
280+
} else if *parallel == 0 {
281+
*parallel = len(plats)
282+
}
283+
throttle := make(chan int, *parallel)
284+
276285
for _, plat := range plats {
277286
wg.Add(1)
278-
fn := func(plat string) {
287+
go func(plat string) {
288+
// block until there's room for this task
289+
throttle <- 1
290+
defer func() {
291+
// indicate this task is done
292+
<-throttle
293+
}()
294+
279295
f := false
280296
serialFprintf(os.Stdout, "type-checking %s\n", plat)
281297
errors, err := c.verify(plat)
@@ -295,12 +311,7 @@ func main() {
295311
failed = failed || f
296312
failMu.Unlock()
297313
wg.Done()
298-
}
299-
if *serial {
300-
fn(plat)
301-
} else {
302-
go fn(plat)
303-
}
314+
}(plat)
304315
}
305316
wg.Wait()
306317
if failed {

0 commit comments

Comments
 (0)