Skip to content

(improvement) cqltypes: fast-path lookup_casstype() for simple type n…#729

Open
mykaul wants to merge 1 commit intoscylladb:masterfrom
mykaul:cql_types_fast_path
Open

(improvement) cqltypes: fast-path lookup_casstype() for simple type n…#729
mykaul wants to merge 1 commit intoscylladb:masterfrom
mykaul:cql_types_fast_path

Conversation

@mykaul
Copy link

@mykaul mykaul commented Mar 6, 2026

…ames

Skip the regex scanner and stack-based parser in parse_casstype_args() when the type string has no parentheses. For simple types like 'AsciiType' or 'org.apache.cassandra.db.marshal.FloatType', go directly to lookup_casstype_simple() which is just a prefix strip + dict lookup.

This avoids re.Scanner, re.split on ':' / '=>', int() try/except, and list-of-lists stack manipulation for the common case of non-parameterized types.

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.

…ames

Skip the regex scanner and stack-based parser in parse_casstype_args()
when the type string has no parentheses. For simple types like
'AsciiType' or 'org.apache.cassandra.db.marshal.FloatType', go directly
to lookup_casstype_simple() which is just a prefix strip + dict lookup.

This avoids re.Scanner, re.split on ':' / '=>', int() try/except, and
list-of-lists stack manipulation for the common case of non-parameterized
types.

Signed-off-by: Yaniv Kaul <yaniv.kaul@scylladb.com>
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

Optimizes Cassandra type-class lookup by short-circuiting lookup_casstype() for non-parameterized (no-parentheses) type strings, avoiding the heavier regex scanner + stack parser for the common case.

Changes:

  • Add a fast-path in lookup_casstype() to directly call lookup_casstype_simple() when the input has no parentheses.
  • Update unit test expectations for malformed simple type names (AsciiType~) to produce an unrecognized type instead of raising ValueError.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
cassandra/cqltypes.py Adds a no-parentheses fast-path in lookup_casstype() to bypass parse_casstype_args() for simple types.
tests/unit/test_types.py Updates lookup_casstype() unit test to reflect the new behavior for malformed simple type names.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mykaul
Copy link
Author

mykaul commented Mar 7, 2026

This is a very small change, which I've split from much larger patchset I'm playing with. I think it's reasonable to get it in by itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants