Skip to content

Commit 5af9571

Browse files
authored
Merge pull request #434 from mdboom/lru-data-cache
Use LRU cache for loading benchmarking data
2 parents feeadc5 + e51a453 commit 5af9571

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

bench_runner/result.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
CombinedData = list[tuple[str, np.ndarray | None, float]]
3535

3636

37+
@functools.lru_cache(maxsize=100)
38+
def _load_contents(filename: Path) -> dict[str, Any]:
39+
with filename.open("rb") as fd:
40+
return json.load(fd)
41+
42+
3743
def _clean(string: str) -> str:
3844
"""
3945
Clean an arbitrary string to be suitable for a filename.
@@ -598,16 +604,15 @@ def result_info(self) -> tuple[str | None, str | None, str | None]:
598604
f"Unknown result type (extra={self.extra} suffix={self.suffix})"
599605
)
600606

601-
@functools.cached_property
607+
@property
602608
def contents(self) -> dict[str, Any]:
603-
with self.filename.open("rb") as fd:
604-
return json.load(fd)
609+
return _load_contents(self.filename)
605610

606-
@property
611+
@functools.cached_property
607612
def metadata(self) -> dict[str, Any]:
608613
return self.contents.get("metadata", {})
609614

610-
@property
615+
@functools.cached_property
611616
def commit_datetime(self) -> str:
612617
if self._commit_datetime is not None:
613618
return self._commit_datetime
@@ -617,7 +622,7 @@ def commit_datetime(self) -> str:
617622
def commit_date(self) -> str:
618623
return self.commit_datetime[:10]
619624

620-
@property
625+
@functools.cached_property
621626
def run_datetime(self) -> str:
622627
return self.contents["benchmarks"][0]["runs"][0]["metadata"]["date"]
623628

0 commit comments

Comments
 (0)