Skip to content

Conversation

@mykaul
Copy link

@mykaul mykaul commented Feb 6, 2026

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

  • [] I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • I added relevant tests for new features and bug fixes.
  • All commits compile, pass static checks and pass test.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have provided docstrings for the public items that I want to introduce.
  • I have adjusted the documentation in ./docs/source/.
  • I added appropriate Fixes: annotations to PR description.

@mykaul mykaul requested a review from Copilot February 6, 2026 12:17
@mykaul mykaul added the enhancement New feature or request label Feb 6, 2026
@mykaul mykaul marked this pull request as draft February 6, 2026 12:17
Copy link

Copilot AI left a 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 to lookup_casstype_simple and parse_casstype_args functions
  • Implemented fast-path optimization in lookup_casstype to 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)
Copy link

Copilot AI Feb 6, 2026

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.

Copilot uses AI. Check for mistakes.
Copy link
Author

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant