Skip to content

Commit 73dec98

Browse files
yaugenst-flexdaquinteroflex
authored andcommitted
perf: add LRU cache to shapely version checking
- Add functools.lru_cache decorator to _shapely_is_older_than() - Remove global _SHAPELY_VERSION variable - Cache up to 8 version comparison results - Reduces repeated parsing of version strings in hot paths
1 parent bcf7112 commit 73dec98

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

tidy3d/compat.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import functools
56
import importlib
67

78
from packaging.version import parse as parse_version
@@ -12,13 +13,9 @@
1213
from xarray.core import alignment
1314

1415

15-
_SHAPELY_VERSION = parse_version(importlib.metadata.version("shapely"))
16-
17-
16+
@functools.lru_cache(maxsize=8)
1817
def _shapely_is_older_than(version: str) -> bool:
19-
if _SHAPELY_VERSION < parse_version(version):
20-
return True
21-
return False
18+
return parse_version(importlib.metadata.version("shapely")) < parse_version(version)
2219

2320

2421
__all__ = ["alignment"]

0 commit comments

Comments
 (0)