Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

perf(proxy): gc.freeze() the startup heap once the proxy is up so gen-2 passes stop re-walking it (#47137)

Kerry Lu1436a8851afc
diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py
index 27bfd03d7f8..1e16eb626fe 100644
--- a/litellm/proxy/proxy_server.py
+++ b/litellm/proxy/proxy_server.py
@@ -1,6 +1,7 @@
import asyncio
import copy
import enum
+import gc
import importlib
import inspect
import io
@@ -1746,6 +1747,8 @@ async def proxy_startup_event(app: FastAPI) -> AsyncGenerator[ProxyLifespanState
async with AsyncExitStack() as admin_mcp_stack:
try:
await admin_mcp_stack.enter_async_context(admin_mcp_lifespan(app))
+ gc.freeze()
+ verbose_proxy_logger.warning("gc.freeze pinned %d startup objects", gc.get_freeze_count())
yield state
finally:
if model_info_scheduler is not None and model_info_scheduler.running: