[llvm] [lit] Use functools.lru_cache for _caching_re_compile (PR #217757)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 20 13:48:14 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-testing-tools

Author: Prasoon Kumar (prasoon054)

<details>
<summary>Changes</summary>

lit.util.memoize builds a (args, tuple(kwargs.items())) key and does two dict lookups per call. functools.lru_cache has a faster path that uses a single positional argument directly as the key, so it does one lookup instead of two and skips the tuple construction.

Profiling lit with Scalene and comparing the two implementations on test suites showed the lru_cache version is faster.

---
Full diff: https://github.com/llvm/llvm-project/pull/217757.diff


1 Files Affected:

- (modified) llvm/utils/lit/lit/TestRunner.py (+2-1) 


``````````diff
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 30a39745d01b9..9ef299d82c118 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -1,6 +1,7 @@
 from __future__ import annotations
 
 import enum
+import functools
 import io
 import os
 import pathlib
@@ -1438,7 +1439,7 @@ def regex_escape(s):
     return substitutions
 
 
- at lit.util.memoize  # Intentionally unbounded: see applySubstitutions
+ at functools.lru_cache(maxsize=None)  # Intentionally unbounded: see applySubstitutions
 def _caching_re_compile(r):
     return re.compile(r)
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/217757


More information about the llvm-commits mailing list