Skip to content

Commit fd64a22

Browse files
authored
Merge pull request #810 from codeflash-ai/codeflash/optimize-pr753-2025-10-10T18.29.30
⚡️ Speed up method `TestsCache.compute_file_hash` by 53% in PR #753 (`test_cache_revival`)
2 parents b210ba4 + c3e2ec2 commit fd64a22

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

codeflash/discovery/discover_unit_tests.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,16 @@ def get_function_to_test_map_for_file(
158158
return result
159159

160160
@staticmethod
161-
def compute_file_hash(path: str | Path) -> str:
161+
def compute_file_hash(path: Path) -> str:
162162
h = hashlib.sha256(usedforsecurity=False)
163-
with Path(path).open("rb") as f:
163+
with path.open("rb", buffering=0) as f:
164+
buf = bytearray(8192)
165+
mv = memoryview(buf)
164166
while True:
165-
chunk = f.read(8192)
166-
if not chunk:
167+
n = f.readinto(mv)
168+
if n == 0:
167169
break
168-
h.update(chunk)
170+
h.update(mv[:n])
169171
return h.hexdigest()
170172

171173
def close(self) -> None:

0 commit comments

Comments
 (0)