refactor: use lru_cache for handler param count

This commit is contained in:
Greyson LaLonde
2026-04-04 21:35:00 +08:00
parent 88d9984178
commit c4bbb039da

View File

@@ -10,17 +10,10 @@ from crewai.events.base_events import BaseEvent
from crewai.events.types.event_bus_types import AsyncHandler, SyncHandler
_handler_param_count: dict[int, int] = {}
@functools.lru_cache(maxsize=256)
def _get_param_count(handler: Any) -> int:
"""Return the number of parameters a handler accepts, with caching."""
key = id(handler)
count = _handler_param_count.get(key)
if count is None:
count = len(inspect.signature(handler).parameters)
_handler_param_count[key] = count
return count
return len(inspect.signature(handler).parameters)
def is_async_handler(