Skip to content

Commit 2d197b2

Browse files
committed
Run gyb generation on multiple threads
This reduces the time to gyb-generate sources from ~12s to ~4s.
1 parent dac63c8 commit 2d197b2

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

build-script.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import subprocess
77
import sys
88
import tempfile
9+
from concurrent.futures import ThreadPoolExecutor
910
from typing import Dict, List, Optional
1011

1112

@@ -206,14 +207,7 @@ def generate_gyb_files_helper(
206207
clear_gyb_files_from_previous_run(
207208
sources_dir, destination_dir, verbose)
208209

209-
# Generate the new .swift files in `temp_files_dir` and only copy them
210-
# to `destiantion_dir` if they are different than the
211-
# files already residing there. This way we don't touch the generated .swift
212-
# files if they haven't changed and don't trigger a rebuild.
213-
for gyb_file in os.listdir(sources_dir):
214-
if not gyb_file.endswith(".gyb"):
215-
continue
216-
210+
def generate_gyb_file(gyb_file):
217211
gyb_file_path = os.path.join(sources_dir, gyb_file)
218212

219213
# Slice off the '.gyb' to get the name for the output file
@@ -230,6 +224,14 @@ def generate_gyb_files_helper(
230224
verbose=verbose,
231225
)
232226

227+
# Generate the new .swift files in `temp_files_dir` and only copy them
228+
# to `destiantion_dir` if they are different than the
229+
# files already residing there. This way we don't touch the generated .swift
230+
# files if they haven't changed and don't trigger a rebuild.
231+
gyb_files = [file for file in os.listdir(sources_dir) if file.endswith(".gyb")]
232+
with ThreadPoolExecutor() as executor:
233+
executor.map(generate_gyb_file, gyb_files)
234+
233235

234236
# Generate the syntax node `.swift` files from `SyntaxNodes.swift.gyb.template`.
235237
# `destination_dir` is not `None`, the resulting files will be written to

0 commit comments

Comments
 (0)