Skip to content

Conversation

@AlexsanderHamir
Copy link
Collaborator

@AlexsanderHamir AlexsanderHamir commented Dec 10, 2025

Title

[Perf] - Cut memory leak in half

Relevant issues

Addresses #12685

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🧹 Refactoring

Changes

  • Remove references from being passed to fire-and-forget tasks.

Results

  • The memory leak is now reduced by more than half.
  • There's still one small memory leak remaining

Before
Screenshot 2025-12-10 at 11 19 46 AM

After

Screenshot 2025-12-10 at 12 09 44 PM

How to look for memory leaks ?

  1. Start the proxy server with a single worker.

  2. In a separate terminal, run:

    memray attach --trace-python-allocators <ProxyServer's PID>
  3. Run a load test against the proxy server.

  4. Stop the load test.

  5. Let the process sit for 5–10 minutes and observe what memory remains.

  6. Sort by % Own

The memory that get_logging_payload was never cleaned even after load tests, indicating a memory leal. Not passing references to helper functions or background tasks solved the issue.
@vercel
Copy link

vercel bot commented Dec 10, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
litellm Ready Ready Preview Comment Dec 10, 2025 8:31pm

@AlexsanderHamir AlexsanderHamir merged commit ccb6cd8 into main Dec 10, 2025
29 of 58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants