perf(providers): let custom-route profile lookups ride the stamp cache

custom:<route> names always miss the exact registry lookup before resolving
to the generic custom profile, so every one forced a plugin-dir stamp re-check
and the 1 s stamp cache never applied to them. The picker resolves them once
per model. They now wait for the periodic check (a plugin registering a named
route is still picked up within the stamp TTL); other misses keep the
immediate re-check. 50 lookups of custom:lab: 50 -> 0 stamp reads,
52.3 -> 9.8 us per call.
This commit is contained in:
kshitijk4poor
2026-09-23 19:33:48 +05:30
committed by kshitij
parent 8b26b57d48
commit 6604b0479e

View File

@@ -164,13 +164,16 @@ def get_provider_profile(name: str) -> ProviderProfile | None:
# A newly installed provider is normally first requested by its new name.
# Refresh that miss immediately so installs remain usable without waiting
# for the periodic stamp check, while known-provider lookups stay hot.
if profile is None:
# ``custom:<route>`` names resolve to the generic profile below on a miss, and
# the picker asks for them once per model, so they wait for the periodic check.
is_custom_route = isinstance(name, str) and name.lower().startswith("custom:")
if profile is None and not is_custom_route:
layer = _home_layer(force_stamp_check=True)
canonical = layer.aliases.get(name) or _ALIASES.get(name, name)
profile = layer.registry.get(canonical) or _REGISTRY.get(canonical)
# Named custom routes share the generic wire policy unless a plugin
# explicitly registered that route. Other names retain exact lookup.
if profile is None and isinstance(name, str) and name.lower().startswith("custom:"):
if profile is None and is_custom_route:
profile = layer.registry.get("custom") or _REGISTRY.get("custom")
return profile