-
Notifications
You must be signed in to change notification settings - Fork 538
perf: use LRU cache for session contexts in get_session_context #5736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: use LRU cache for session contexts in get_session_context #5736
Conversation
Previously, get_session_context only cached session contexts when options matched hardcoded defaults. This meant setting LANCE_MEM_POOL_SIZE env var would cause cache misses every time, creating a new SessionContext on each call. Now uses an LRU cache (size 4) keyed by resolved configuration values, so repeated calls with the same effective configuration reuse cached contexts regardless of whether values come from defaults, explicit options, or environment variables. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Code ReviewP1: Missing test coverage for new caching logicThe new LRU cache implementation has no unit tests. Given this code manages shared state (global cache with mutex), I'd recommend adding tests to verify:
P1: Consider using
|
Tests verify: - Caching works (same options reuse cached context) - Different options create separate cache entries - LRU eviction order (least recently accessed is evicted first) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
7ca8443 to
822c5f1
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Use unwrap_or_else with into_inner() to recover from PoisonError instead of panicking. The cache data remains valid even if a thread panicked while holding the lock. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tests share global cache state and were failing when run in parallel. Add a test-only Mutex to ensure they run sequentially. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…e-format#5736) We have a performance issue when `LANCE_MEM_POOL_SIZE`: when this is set (to something different than the default), the current cache always misses here: https://github.com/lance-format/lance/blob/445dd5bfe7b0111fd8e146163393e825e5995679/rust/lance-datafusion/src/exec.rs#L398-L410 - Replace static `LazyLock` session contexts with LRU cache (size 4) - Cache key uses resolved configuration values (after env var lookup) - Fixes cache misses when `LANCE_MEM_POOL_SIZE` env var is set - [x] `cargo test -p lance-datafusion` passes - [x] `cargo clippy -p lance-datafusion` passes 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
…e-format#5736) ## Motivation We have a performance issue when `LANCE_MEM_POOL_SIZE`: when this is set (to something different than the default), the current cache always misses here: https://github.com/lance-format/lance/blob/445dd5bfe7b0111fd8e146163393e825e5995679/rust/lance-datafusion/src/exec.rs#L398-L410 ## Summary - Replace static `LazyLock` session contexts with LRU cache (size 4) - Cache key uses resolved configuration values (after env var lookup) - Fixes cache misses when `LANCE_MEM_POOL_SIZE` env var is set ## Test plan - [x] `cargo test -p lance-datafusion` passes - [x] `cargo clippy -p lance-datafusion` passes 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
We have a performance issue when `LANCE_MEM_POOL_SIZE`: when this is set (to something different than the default), the current cache always misses here: https://github.com/lance-format/lance/blob/445dd5bfe7b0111fd8e146163393e825e5995679/rust/lance-datafusion/src/exec.rs#L398-L410 - Replace static `LazyLock` session contexts with LRU cache (size 4) - Cache key uses resolved configuration values (after env var lookup) - Fixes cache misses when `LANCE_MEM_POOL_SIZE` env var is set - [x] `cargo test -p lance-datafusion` passes - [x] `cargo clippy -p lance-datafusion` passes 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Motivation
We have a performance issue when
LANCE_MEM_POOL_SIZE: when this is set (to something different than the default), the current cache always misses here:lance/rust/lance-datafusion/src/exec.rs
Lines 398 to 410 in 445dd5b
Summary
LazyLocksession contexts with LRU cache (size 4)LANCE_MEM_POOL_SIZEenv var is setTest plan
cargo test -p lance-datafusionpassescargo clippy -p lance-datafusionpasses🤖 Generated with Claude Code