-
Notifications
You must be signed in to change notification settings - Fork 50
(improvement)Optimize custom type parsing with LRU caching #690
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
base: master
Are you sure you want to change the base?
Conversation
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 pull request optimizes custom type parsing by adding LRU caching to frequently-called type lookup functions and implementing a fast path for simple types without parameters. The optimization aims to reduce repeated string manipulation and regex scanning for type lookups that occur frequently during query execution.
Changes:
- Added
@functools.lru_cache(maxsize=256)decorators tolookup_casstype_simpleandparse_casstype_argsfunctions - Implemented fast-path optimization in
lookup_casstypeto avoid regex scanning for simple types (those without parentheses) - Removed error handling wrapper from
lookup_casstype, changing behavior to return UnrecognizedType instead of raising ValueError for invalid types - Added benchmark script demonstrating cache effectiveness for repeated type lookups
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 10 comments.
| File | Description |
|---|---|
| cassandra/cqltypes.py | Added LRU caching to type parsing functions, removed error handling wrapper, cleaned up unused variable, optimized type lookup with fast path |
| tests/unit/test_types.py | Updated test to reflect new behavior where invalid type names create UnrecognizedType instead of raising ValueError |
| benchmarks/cache_benefit.py | New benchmark script demonstrating LRU cache benefits for repeated type lookups with various type complexities |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return typeclass | ||
|
|
||
|
|
||
| @functools.lru_cache(maxsize=256) |
Copilot
AI
Feb 6, 2026
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.
The LRU cache size of 256 entries may be insufficient for large multi-tenant systems with many different schemas. Consider making the cache size configurable or using a larger default value. In systems with hundreds of tables and complex nested types, the cache could thrash, reducing the effectiveness of the optimization. Monitor cache hit rates in production to determine if the size needs adjustment.
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.
I think it's good enough.
Cache lookup_casstype_simple() and parse_casstype_args() to avoid repeated string manipulation and regex scanning. Adds fast path for simple types without parameters. Added a small benchmark as well. Signed-off-by: Yaniv Kaul <yaniv.kaul@scylladb.com>
Cache lookups of types to avoid repeated string manipulation and regex scanning. Adds fast path for simple types without parameters.
Added a small benchmark as well.
Pre-review checklist
./docs/source/.Fixes:annotations to PR description.