perf: cache inspect.signature() at decoration time in logged_command and cache decorators #97
Labels
No Label
ai-changes-requested
ai-pr-opened
ai-reviewed
ai-reviewing
ai-working
in-next-release
status/in-progress
status/pr-open
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/major-domo-v2#97
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
utils/decorators.pycallsinspect.signature(func)inside the wrapper function — meaning it runs on every invocation of any@logged_command,@cached_api_call, or@cached_single_itemdecorated function.Locations
logged_commandwrapper, lines 66–72: called on every slash command invocationcached_api_callwrapper, lines 219–221: called on every cache misscached_single_itemwrapper, lines 277–279: called on every cache missinspect.signature()introspects function objects, annotations, and code — it's not trivially cheap.Fix
Compute the signature once at decoration time (in the outer
decoratorfunction), then close over the result:Impact
LOW-MEDIUM — Every slash command invocation pays this cost. Under high autocomplete activity it compounds.
PR #107 opened: #107
Moved
inspect.signature(func)from inside wrapper functions to the outerdecoratorfunction in all three locations (logged_command,cached_api_call,cached_single_item). The signature is now computed once at decoration time and closed over by the wrapper.wrapper.__signature__inlogged_commandalso reuses the pre-computedsiginstead of calling it a second time. 11/11 decorator tests pass.