Avatar for the langchain-ai user
langchain-ai
langchain
Instrumentation
Wall Time
BlogDocsChangelog

fix: prevent memory leak in get_usage_metadata_callback

#32366Closed
Comparing
20ns:fix/usage-metadata-callback-memory-leak-v2
(
926fbfb
) with
master
(
9a2f49d
)
CodSpeed Performance Gauge
0%
Improvements
0
Regressions
0
Untouched
14
New
0
Dropped
0
Ignored
0

Benchmarks

Passed

test_init_time_with_client
libs/partners/anthropic/tests/unit_tests/test_standard.py::test_init_time_with_client
CodSpeed Performance Gauge
0%
5.2 ms
5.2 ms
test_init_time
libs/partners/openai/tests/unit_tests/chat_models/test_responses_standard.py::TestOpenAIResponses::test_init_time
CodSpeed Performance Gauge
0%
17.2 ms
17.1 ms
test_init_time
libs/partners/openai/tests/unit_tests/chat_models/test_base_standard.py::TestOpenAIStandard::test_init_time
CodSpeed Performance Gauge
0%
17.1 ms
17.1 ms
test_init_time
libs/partners/mistralai/tests/unit_tests/test_standard.py::TestMistralStandard::test_init_time
CodSpeed Performance Gauge
0%
12.5 ms
12.5 ms
test_stream_time
libs/partners/openai/tests/integration_tests/chat_models/test_base_standard.py::TestOpenAIStandard::test_stream_time
CodSpeed Performance Gauge
0%
1.1 s
1.1 s
test_init_time
libs/partners/groq/tests/unit_tests/test_standard.py::TestGroqStandard::test_init_time
CodSpeed Performance Gauge
0%
1.6 s
1.6 s
test_init_time
libs/partners/openai/tests/unit_tests/chat_models/test_azure_standard.py::TestOpenAIStandard::test_init_time
CodSpeed Performance Gauge
0%
1.7 s
1.7 s
test_init_time
libs/partners/deepseek/tests/unit_tests/test_chat_models.py::TestChatDeepSeekUnit::test_init_time
CodSpeed Performance Gauge
0%
1.6 s
1.6 s
test_init_time
libs/partners/xai/tests/unit_tests/test_chat_models_standard.py::TestXAIStandard::test_init_time
CodSpeed Performance Gauge
0%
3.3 s
3.3 s
test_init_time
libs/partners/fireworks/tests/unit_tests/test_standard.py::TestFireworksStandard::test_init_time
CodSpeed Performance Gauge
0%
6.6 s
6.6 s
test_stream_time
libs/partners/openai/tests/integration_tests/chat_models/test_responses_standard.py::TestOpenAIStandard::test_stream_time
CodSpeed Performance Gauge
0%
1.1 s
1.1 s
test_stream_time
libs/partners/openai/tests/integration_tests/chat_models/test_responses_standard.py::TestOpenAIResponses::test_stream_time
CodSpeed Performance Gauge
0%
926 ms
926.5 ms
test_init_time
libs/partners/anthropic/tests/unit_tests/test_standard.py::TestAnthropicStandard::test_init_time
CodSpeed Performance Gauge
0%
3.7 ms
3.7 ms
test_stream_time
libs/partners/anthropic/tests/integration_tests/test_standard.py::TestAnthropicStandard::test_stream_time
CodSpeed Performance Gauge
0%
15.8 ms
15.9 ms

Commits

Click on a commit to change the comparison range
Base
master
9a2f49d
0%
fix: use ContextVar cache to prevent memory leak Use a simple module-level cache (_registered_context_vars) to store and reuse ContextVar instances by name. This prevents the memory leak in _configure_hooks while maintaining the original API. Changes: - Add _registered_context_vars cache dict at module level - Reuse existing ContextVar instances instead of creating new ones - Only register hooks once per unique name - Update test to verify cache behavior instead of internal hooks - Maintain full backward compatibility
86a035b
1 day ago
by 20ns
0%
fix: improve memory leak test to avoid conflicts Make test more robust by: - Using unique test name to avoid conflicts with other tests - Cleaning up test data before and after - More focused assertions - Proper test isolation
8d98a0b
1 day ago
by 20ns
0%
fix: simplify type annotations for linting Remove complex type annotations that may be causing linting issues: - Use dict[str, Any] instead of complex ContextVar generic - Remove inline type annotation for variable - Maintain functionality while fixing lint issues
926fbfb
1 day ago
by 20ns
© 2025 CodSpeed Technology
Home Terms Privacy Docs