From 88856e6b139c761e7876b1cd3b29e8dad236d8c7 Mon Sep 17 00:00:00 2001 From: Wei-Ting Chen Date: Tue, 20 Aug 2024 16:45:45 +0800 Subject: [PATCH] Put cheap check first in testingTriggerSpill() (#10646) (#494) Summary: testingTriggerSpill() uses 1% cpu in meta internal profiling on release build. This is due to the expensive regex check it does upon entrance of this method. Move pct check up to avoid regex check to reduce the cpu consumption. Pull Request resolved: https://github.com/facebookincubator/velox/pull/10646 Reviewed By: kevinwilfong Differential Revision: D60613614 Pulled By: tanjialiang fbshipit-source-id: 23cbfc89b575343b7e7da1dd7d0eaef63a1ec705 Co-authored-by: Jialiang Tan --- velox/exec/Spill.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/velox/exec/Spill.cpp b/velox/exec/Spill.cpp index ee0c9be573e3..f7776566864c 100644 --- a/velox/exec/Spill.cpp +++ b/velox/exec/Spill.cpp @@ -338,11 +338,7 @@ tsan_atomic& injectedSpillCount() { } bool testingTriggerSpill(const std::string& pool) { - // Do not evaluate further if trigger is not set. - if (!pool.empty() && !RE2::FullMatch(pool, testingSpillPoolRegExp())) { - return false; - } - + // Put cheap check first to reduce CPU consumption in release code. if (testingSpillPct() <= 0) { return false; } @@ -355,6 +351,10 @@ bool testingTriggerSpill(const std::string& pool) { return false; } + if (!pool.empty() && !RE2::FullMatch(pool, testingSpillPoolRegExp())) { + return false; + } + ++injectedSpillCount(); return true; }