-
Notifications
You must be signed in to change notification settings - Fork 15
perf: performance-driven re-design #81
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
Conversation
35187e1
to
25a71d9
Compare
e1e055b
to
718ab9b
Compare
2c4f5ea
to
07baa3e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This release introduces significant performance improvements for the Redis checkpoint implementation through architectural changes and new features. The PR upgrades the package to v0.1.0 with breaking changes to the internal storage format and key structure.
Key improvements include:
- Performance-driven redesign with 50-70% reduction in Redis operations for typical workflows
- New checkpoint-based key registry using sorted sets instead of expensive SCAN/KEYS operations
- Multi-level caching for frequently accessed keys and data with lazy TTL refresh
- Inline storage for shallow checkpoints eliminating separate blob operations
Reviewed Changes
Copilot reviewed 68 out of 73 changed files in this pull request and generated 8 comments.
Show a summary per file
File | Description |
---|---|
pyproject.toml | Version bump to 0.1.0 and new dependencies for performance optimization |
langgraph/checkpoint/redis/version.py | Dynamic version loading from package metadata with pyproject.toml fallback |
langgraph/checkpoint/redis/shallow.py | Major redesign with inline storage, thread-level registries, and performance caching |
tests/ | Comprehensive test coverage for new functionality including version loading, shallow operations, and key registry |
scripts.py | Enhanced test commands with coverage reporting and code quality tools |
f2f4520
to
033c82c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of non-blocking thoughts:
- Would it make sense to add a MIGRATION.md or a README section on "Upgrading to [whatever version]" that says old checkpoints are incompatible and that new indices/fields are required? And call out that existing data will not be auto-backfilled?
- Maybe an lur_cache instead of dict for the key cache
BREAKING CHANGE: This release introduces significant performance improvements that change the internal storage format and key structure. Checkpoints created with earlier versions are incompatible with v0.1.0. Key performance improvements: - Replace some FT.SEARCH operations with sorted sets for write tracking - Add checkpoint-based key registry eliminating expensive SCAN/KEYS operations - Implement multi-level caching for frequently accessed keys and data - Optimize batch operations with pipelined Redis commands - Add lazy TTL refresh to reduce unnecessary operations - Improve index schemas for better query performance Architectural changes: - New CheckpointKeyRegistry tracks writes per checkpoint using sorted sets - Cached key generation methods reduce string concatenation overhead - Batch loading methods for pending writes and sends - Optimized get_tuple with direct document access patterns - Improved TTL management with threshold-based refresh Testing improvements: - Add comprehensive test coverage for new registry functionality - Test TTL behaviors, caching mechanisms, and error paths - Add integration tests for blob handling and metadata operations - Improve test isolation using unique thread IDs instead of flushdb The new architecture provides: - 50-70% reduction in Redis operations for typical workflows - Better scalability with checkpoint-scoped write tracking - Reduced memory footprint through efficient caching - Improved cluster mode compatibility
BREAKING CHANGE: This release introduces significant performance improvements that change the internal storage format and key structure. Checkpoints created with earlier versions are incompatible with v0.1.0.
Key performance improvements:
Architectural changes:
Testing improvements:
The new architecture provides:
Redis Checkpoint Optimization Guide
Overview
This document details the architectural and design changes made to optimize Redis checkpoint operations between baseline commit 8e87eba and version 0.1.0.
Major Architectural Changes
1. Key Registry System
File Added:
langgraph/checkpoint/redis/key_registry.py
It introduces:
write_keys_zset:{thread_id}:{namespace}:{checkpoint_id}
2. Inline Channel Values Storage
Before (Baseline):
checkpoint_blob:{thread_id}:{namespace}:{channel}:{version}
get_channel_values()
method performed multiple searchesAfter (Optimized):
Storage Structure Change:
Operation-Specific Changes
1. List Checkpoints Operation (
alist
)Regular Async (
aio.py
)New Method Added:
_abatch_load_pending_writes
Before (Baseline):
_aload_pending_writes
individually for each checkpointAfter (Optimized):
Complexity Change:
2. Get Channel Values Operation
All Implementations
Before (Baseline):
After (Optimized):
Complexity Change:
3. Load Pending Writes Operation
Before (Baseline)
After (Optimized)
4. Put Checkpoint Operation
Changes in Storage Logic
Before:
After:
has_writes
flag on checkpoint5. Async-Specific Optimizations
Get Checkpoint (
aget_tuple
inaio.py
)asyncio.gather()
to parallelize independent operationsList Checkpoints (
_abatch_load_pending_writes
inaio.py
)Put Checkpoint (Shallow Async)
Added Methods
_abatch_load_pending_writes()
- Batch loading for list operations_deserialize_channel_values()
- Handle inline channel values_recursive_deserialize()
- Reconstruct LangChain objects_make_*_cached()
methods - Cached key generationModified Storage Fields
checkpoint_ts
- Added for timestamp querieshas_writes
- Added to track write existencechannel_values
- Added inline to checkpoint documentStack Changes
Libraries
json
libraryorjson
for faster JSON serialization/deserializationRedis Features Used
Complexity Analysis
Where:
⛓️💥 Breaking Changes
Migration Warning⚠️ CRITICAL
This optimized version CANNOT be used as a drop-in replacement. Multiple read operations will fail when encountering old checkpoints that store channel values in separate blob documents.
Operations That WILL FAIL With Old Checkpoints
{}
instead of actual data (NO FALLBACK)