perf: optimize gateway cold start from ~6.9s to ~460ms (#3918)

Channel lazy load: discover_enabled() only imports enabled channel
modules instead of all 18 modules with heavy SDKs (telegram, discord,
slack, etc). discover_all() now delegates to discover_enabled().

Lazy OpenAI client: defer AsyncOpenAI() + httpx construction to
_ensure_client() with asyncio.Lock double-checked locking. openai
and httpx imports moved from module-level into _ensure_client().

Minor: lazy Nanobot/RunResult and CronService exports via __getattr__.

Benchmark: 6910ms → 460ms (-93.3%)
This commit is contained in:
chengyongru
2026-05-20 12:02:23 +08:00
committed by Xubin Ren
parent 1391aa3d57
commit af9f8d54b8
9 changed files with 173 additions and 74 deletions
@@ -29,7 +29,7 @@ def test_openai_compat_provider_sets_timeout_on_local_http_client() -> None:
with (
patch("nanobot.providers.openai_compat_provider.AsyncOpenAI") as mock_async_openai,
patch(
"nanobot.providers.openai_compat_provider.httpx.AsyncClient",
"httpx.AsyncClient",
return_value=sentinel.http_client,
) as mock_http_client,
):