Skip to content

Commit c18312f

Browse files
Perf: Optimized the line split logic in mySpawn() to generate fewer commands.
In `my_spawn.py`, the command line length cannot exceed 32000 characters on windows. The previous implementation would break down linking to one `.obj` file at a time which was extremely slow. The new batching logic instead will batch as many `.obj` files as possible into a single linking operation resulting in significantly faster build times when compiling using MinGW on Windows.
1 parent db53da2 commit c18312f

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

tools/my_spawn.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,23 @@ def mySpawn(sh, escape, cmd, args, env):
3737

3838
rv = 0
3939
if len(cmdline) > 32000 and cmd.endswith("ar"):
40-
cmdline = cmd + " " + args[1] + " " + args[2] + " "
41-
for i in range(3, len(args)):
42-
rv = mySubProcess(cmdline + args[i], env)
40+
cmdline_base = cmd + " " + args[1] + " " + args[2] + " "
41+
42+
i = 3
43+
while i < len(args):
44+
batch_args = []
45+
current_len = len(cmdline_base)
46+
47+
while i < len(args) and current_len + len(args[i]) + 1 < 32000:
48+
batch_args.append(args[i])
49+
current_len += len(args[i]) + 1
50+
i += 1
51+
52+
if not batch_args: # Should not happen unless a single arg is > 32000
53+
batch_args.append(args[i])
54+
i += 1
55+
56+
rv = mySubProcess(cmdline_base + " ".join(batch_args), env)
4357
if rv:
4458
break
4559
else:

0 commit comments

Comments
 (0)