From 6604b0479ee1ee7b129454266fead7a37cbc0f90 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Wed, 23 Sep 2026 19:33:48 +0530 Subject: [PATCH] perf(providers): let custom-route profile lookups ride the stamp cache custom: 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. --- providers/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/providers/__init__.py b/providers/__init__.py index c9f056e940..3e771fba98 100644 --- a/providers/__init__.py +++ b/providers/__init__.py @@ -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:`` 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