From 6b7e8341748811ceb77d63bd6d5b2ad100bdb2b3 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 23 Apr 2026 14:23:27 -0500 Subject: [PATCH] [ci] Always print top import-time offenders, not just on regression MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Seeing the top contributors every run — regression or not — gives reviewers and future-PR authors a running reference for which imports are currently most expensive. That's the data we need to prioritize lazy-import refactors, so there's no reason to hide it on pass. --- script/check_import_time.py | 41 +++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/script/check_import_time.py b/script/check_import_time.py index 7b405475c3..1c25a3cdd6 100755 --- a/script/check_import_time.py +++ b/script/check_import_time.py @@ -146,27 +146,32 @@ def cmd_check(args: argparse.Namespace) -> int: f"measured {TARGET_MODULE}: {_format_us(measured)} " f"(budget {_format_us(baseline)} + {margin_pct}% = {_format_us(ceiling)})" ) + passed = measured <= ceiling + stream = sys.stdout if passed else sys.stderr - if measured <= ceiling: + if passed: print(summary) - return 0 + else: + print( + f"REGRESSION: `import {TARGET_MODULE}` took {_format_us(measured)}, " + f"exceeding the budget of {_format_us(baseline)} + {margin_pct}% " + f"({_format_us(ceiling)}).", + file=stream, + ) - print( - f"REGRESSION: `import {TARGET_MODULE}` took {_format_us(measured)}, " - f"exceeding the budget of {_format_us(baseline)} + {margin_pct}% " - f"({_format_us(ceiling)}).\n" - f"Top import-time offenders (by self time):", - file=sys.stderr, - ) - _print_offenders_table(top_offenders(har, OFFENDERS_TOP_N), sys.stderr) - print( - "\nIf this regression is intentional, regenerate the budget with:\n" - " script/check_import_time.py --update\n" - "Otherwise, consider making the new import lazy " - "(import inside the function that uses it).", - file=sys.stderr, - ) - return 1 + print("\nTop import-time offenders (by self time):", file=stream) + _print_offenders_table(top_offenders(har, OFFENDERS_TOP_N), stream) + + if not passed: + print( + "\nIf this regression is intentional, regenerate the budget with:\n" + " script/check_import_time.py --update\n" + "Otherwise, consider making the new import lazy " + "(import inside the function that uses it).", + file=stream, + ) + return 1 + return 0 def cmd_update(args: argparse.Namespace) -> int: