Skip to content

Perf: cheaper request cycle and cold path #573

Closed

Description

@lesnik512

This was generated by AI during a pre-4.0 audit of main at 9cd88e7.

Warm resolve is at its floor. Measured on CPython 3.14.7 (cross-checked 3.11-3.13), full suite green against the patched copy:

Change Where Effect
CacheRegistry and ContextRegistry as plain __slots__ classes; build ContextRegistry positionally cache_registry.py:72, context_registry.py:7, container.py:88-89 kw-only dataclass call 138 ns vs 63 ns positional; G6 -19%, G7 -6%
Memoize compiled code on a tuple key (arity, names, static, cached) instead of the frozen _Shape dataclass resolver_compiler.py:190-196 G8 cold 24.4 -> 20.8 us (-15%)
Inline find_context into the ContextProvider resolver (keep in + []) resolver_compiler.py:280 direct context resolve 160 -> 134 ns, G9 -6%; removes a second frame per context node
Skip the cache close when nothing was created container.py:213,221 request cycle with nothing cached -6 to -11%

Dropping abc.ABC from AbstractProvider (another G8 -4%, Marker.resolve -30%) is in the provider-surface issue.

Rejected: building the child via object.__new__ (another -15-20% on G6 but duplicates construction logic) and is instead of == for scope checks (3.14-only gain).

Acceptance

Before/after numbers for G6, G7, G8, G9 in the PR; frame-budget test still green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestready-for-agentFully specified, ready for an AFK agent

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions