From 104600ae09d251bc1abbdcfce600204f237db1b1 Mon Sep 17 00:00:00 2001 From: William Allen Date: Wed, 18 Nov 2026 09:22:00 -0500 Subject: [PATCH] Speed up test diff and timing calculations When CDash processes test results, it compares each test with the same test in the previous build. That comparison is used to count new passes and failures and to update test timing statistics. Both steps searched the previous build's whole test list for every test, so processing slowed down sharply as the number of tests grew. This change builds a lookup by test name once and uses it instead. In benchmarks of the comparison loops, a build with 5,000 tests went from 26 s to 13 ms. --- app/Utils/TestDiffUtil.php | 6 ++++-- app/cdash/app/Model/Build.php | 4 ++-- phpstan-baseline.neon | 6 ------ 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/Utils/TestDiffUtil.php b/app/Utils/TestDiffUtil.php index c4a59bd2d2..ea032d03b1 100755 --- a/app/Utils/TestDiffUtil.php +++ b/app/Utils/TestDiffUtil.php @@ -66,8 +66,9 @@ private static function computeDifferencesForType(Build $build, Build $previous_ // has changed since the previous build. $newstatus_b2t_ids = []; + $previous_test_names = array_flip(array_column($previous_tests, 'name')); foreach ($tests as $test) { - if (array_search($test['name'], array_column($previous_tests, 'name')) === false) { + if (!isset($previous_test_names[$test['name']])) { // This test was found for the current build but not the previous build. $num_positive++; $newstatus_b2t_ids[] = $test['buildtestid']; @@ -78,8 +79,9 @@ private static function computeDifferencesForType(Build $build, Build $previous_ Test::whereIn('id', $newstatus_b2t_ids) ->update(['newstatus' => 1]); + $test_names = array_flip(array_column($tests, 'name')); foreach ($previous_tests as $previous_test) { - if (array_search($previous_test['name'], array_column($tests, 'name')) === false) { + if (!isset($test_names[$previous_test['name']])) { // This test had status=$type in the previous build, but it doesn't any more. $num_negative++; } diff --git a/app/cdash/app/Model/Build.php b/app/cdash/app/Model/Build.php index b8d52f068f..b764ad5c75 100644 --- a/app/cdash/app/Model/Build.php +++ b/app/cdash/app/Model/Build.php @@ -1177,13 +1177,13 @@ public function ComputeTestTiming(): bool $testtimestatusfailed = 0; // Get the tests performed by the previous build. - $previous_tests = Test::where('buildid', $previousbuildid)->get(); + $previous_tests = Test::where('buildid', $previousbuildid)->get()->keyBy('testname'); // Loop through the tests performed by this build. $current_tests = Test::where('buildid', $this->Id)->get(); /** @var Test $current_test */ foreach ($current_tests as $current_test) { - $previous_test = $previous_tests->firstWhere('testname', $current_test->testname); + $previous_test = $previous_tests->get($current_test->testname); if ($previous_test !== null) { if ($current_test->status === 'passed') { // if the current test passed diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index db085b3a27..ed5e7ffaf3 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -5841,12 +5841,6 @@ parameters: count: 2 path: app/Utils/TestDiffUtil.php - - - rawMessage: 'Call to function array_search() requires parameter #3 to be set.' - identifier: function.strict - count: 2 - path: app/Utils/TestDiffUtil.php - - rawMessage: 'Only booleans are allowed in an if condition, stdClass|null given.' identifier: if.condNotBoolean