Skip to content

Commit ad130e8

Browse files
committed
Parallelize finding board settings
This reduces the _elapsed_ time running the script from ~90s to ~15s on my AMD Ryzen 7 5700U. The CPU time is still around 2 minutes.
1 parent 2516403 commit ad130e8

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

tools/ci_set_matrix.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import json
2121
import yaml
2222
import pathlib
23+
from concurrent.futures import ThreadPoolExecutor
2324

2425
tools_dir = pathlib.Path(__file__).resolve().parent
2526
top_dir = tools_dir.parent
@@ -28,7 +29,11 @@
2829
sys.path.insert(0, str(top_dir / "docs"))
2930

3031
import build_board_info
31-
from shared_bindings_matrix import get_settings_from_makefile
32+
from shared_bindings_matrix import (
33+
get_settings_from_makefile,
34+
SUPPORTED_PORTS,
35+
all_ports_all_boards,
36+
)
3237

3338
PORT_TO_ARCH = {
3439
"atmel-samd": "arm",
@@ -86,6 +91,20 @@ def set_boards_to_build(build_all):
8691
port_to_boards[port].add(board_id)
8792
board_to_port[board_id] = port
8893

94+
def compute_board_settings():
95+
if board_settings:
96+
return
97+
98+
def get_settings(arg):
99+
board = arg[1].name
100+
return (
101+
board,
102+
get_settings_from_makefile(str(top_dir / "ports" / board_to_port[board]), board),
103+
)
104+
105+
with ThreadPoolExecutor(max_workers=os.cpu_count()) as ex:
106+
board_settings.update(ex.map(get_settings, all_ports_all_boards()))
107+
89108
boards_to_build = all_board_ids
90109

91110
if not build_all:
@@ -123,11 +142,8 @@ def set_boards_to_build(build_all):
123142
# As a (nearly) last resort, for some certain files, we compute the settings from the
124143
# makefile for each board and determine whether to build them that way.
125144
if p.startswith("frozen") or p.startswith("supervisor") or module_matches:
145+
compute_board_settings()
126146
for board in all_board_ids:
127-
if board not in board_settings:
128-
board_settings[board] = get_settings_from_makefile(
129-
str(top_dir / "ports" / board_to_port[board]), board
130-
)
131147
settings = board_settings[board]
132148

133149
# Check frozen files to see if they are in each board.

0 commit comments

Comments
 (0)