Skip to content

Commit 89f583a

Browse files
committed
refresh.template.py: Estimate the number of actions that can be run based on timeout
1 parent bd7bde1 commit 89f583a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

refresh.template.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -831,11 +831,20 @@ def _convert_compile_commands(aquery_output, focused_on_file: str = None):
831831
max_workers=min(32, (os.cpu_count() or 1) + 4) # Backport. Default in MIN_PY=3.8. See "using very large resources implicitly on many-core machines" in https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor
832832
) as threadpool:
833833
found_header_focused_upon = threading.Event() # MIN_PY=3.9: Consider replacing with threadpool.shutdown(cancel_futures=True), possibly also eliminating threading import
834+
timeout = 3
835+
measure_action_count = len(aquery_output.actions) if not focused_on_file else 100
836+
measure_start_time = time.time()
834837
output_iterator = threadpool.map(
835838
lambda compile_action: _get_cpp_command_for_files(compile_action, found_header_focused_upon, focused_on_file), # Binding along side inputs
836-
aquery_output.actions,
837-
timeout=3 if focused_on_file else None # If running in fast, interactive mode with --file, we need to cap latency. #TODO test timeout--if it doesn't work, cap input length here, before passing in array. Might also want to divide timeout/cap by #targets
839+
aquery_output.actions[:measure_action_count]
838840
)
841+
cost_time = time.time() - measure_start_time
842+
if focused_on_file and cost_time < timeout:
843+
estimate_action_count = min(int((timeout - cost_time) / cost_time * measure_action_count), 5000)
844+
output_iterator = itertools.chain(output_iterator, threadpool.map(
845+
lambda compile_action: _get_cpp_command_for_files(compile_action, found_header_focused_upon, focused_on_file), # Binding along side inputs
846+
aquery_output.actions[measure_action_count:measure_action_count + estimate_action_count]
847+
))
839848
# Collect outputs, tolerating any timeouts
840849
outputs = []
841850
try:

0 commit comments

Comments
 (0)