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
-3%
Improvements
0
Regressions
0
Untouched
13
New
0
Dropped
0
Ignored
0

Benchmarks

Passed

test_async_callbacks_in_sync
libs/core/tests/benchmarks/test_async_callbacks.py::test_async_callbacks_in_sync
CodSpeed Performance Gauge
-1%
23.8 ms
24 ms
test_import_time[Runnable]
libs/core/tests/benchmarks/test_imports.py::test_import_time[Runnable]
CodSpeed Performance Gauge
-2%
226.4 ms
229.9 ms
test_import_time[tool]
libs/core/tests/benchmarks/test_imports.py::test_import_time[tool]
CodSpeed Performance Gauge
-2%
460.9 ms
470.6 ms
test_import_time[RunnableLambda]
libs/core/tests/benchmarks/test_imports.py::test_import_time[RunnableLambda]
CodSpeed Performance Gauge
-2%
227.9 ms
233.6 ms
test_import_time[InMemoryVectorStore]
libs/core/tests/benchmarks/test_imports.py::test_import_time[InMemoryVectorStore]
CodSpeed Performance Gauge
-2%
238.3 ms
244.4 ms
test_import_time[ChatPromptTemplate]
libs/core/tests/benchmarks/test_imports.py::test_import_time[ChatPromptTemplate]
CodSpeed Performance Gauge
-3%
409.3 ms
421 ms
test_import_time[HumanMessage]
libs/core/tests/benchmarks/test_imports.py::test_import_time[HumanMessage]
CodSpeed Performance Gauge
-3%
206.1 ms
212.1 ms
test_import_time[CallbackManager]
libs/core/tests/benchmarks/test_imports.py::test_import_time[CallbackManager]
CodSpeed Performance Gauge
-3%
413.5 ms
427.4 ms
test_import_time[Document]
libs/core/tests/benchmarks/test_imports.py::test_import_time[Document]
CodSpeed Performance Gauge
-4%
205.2 ms
212.9 ms
test_import_time[BaseChatModel]
libs/core/tests/benchmarks/test_imports.py::test_import_time[BaseChatModel]
CodSpeed Performance Gauge
-4%
482.4 ms
501.6 ms
test_import_time[InMemoryRateLimiter]
libs/core/tests/benchmarks/test_imports.py::test_import_time[InMemoryRateLimiter]
CodSpeed Performance Gauge
-5%
162.1 ms
169.8 ms
test_import_time[PydanticOutputParser]
libs/core/tests/benchmarks/test_imports.py::test_import_time[PydanticOutputParser]
CodSpeed Performance Gauge
-5%
357.5 ms
374.7 ms
test_import_time[LangChainTracer]
libs/core/tests/benchmarks/test_imports.py::test_import_time[LangChainTracer]
CodSpeed Performance Gauge
-5%
403.4 ms
424.9 ms

Commits

Click on a commit to change the comparison range
Base
master
9a2f49d
-1%
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
3 days ago
by 20ns
-3%
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
3 days 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
3 days ago
by 20ns
© 2025 CodSpeed Technology
Home Terms Privacy Docs