Skip to content

Commit a9a79c3

Browse files
committed
Cache importlib_metadata.entry_points
1 parent 64de448 commit a9a79c3

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

opentelemetry-api/src/opentelemetry/util/_importlib_metadata.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,33 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# FIXME: Use importlib.metadata when support for 3.11 is dropped if the rest of
16-
# the supported versions at that time have the same API.
15+
from functools import lru_cache
16+
1717
from importlib_metadata import ( # type: ignore
1818
Distribution,
1919
EntryPoint,
2020
EntryPoints,
2121
PackageNotFoundError,
2222
distributions,
23-
entry_points,
2423
requires,
2524
version,
2625
)
26+
from importlib_metadata import (
27+
entry_points as original_entry_points,
28+
)
29+
30+
31+
@lru_cache()
32+
def _original_entry_points_cached():
33+
return original_entry_points()
34+
35+
36+
def entry_points(**params):
37+
"""Replacement for importlib_metadata.entry_points that caches getting all the entry points.
38+
39+
That part can be very slow, and OTel uses this function many times."""
40+
return _original_entry_points_cached().select(**params)
41+
2742

2843
__all__ = [
2944
"entry_points",

0 commit comments

Comments
 (0)