forked from apache/cassandra
-
Notifications
You must be signed in to change notification settings - Fork 21
CNDB-13162: Optimize Component.Type pattern matching by pre-compiling regex patterns #2104
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Checklist before you submit for review
|
|
✔️ Build ds-cassandra-pr-gate/PR-2104 approved by ButlerApproved by Butler |
eolivelli
approved these changes
Nov 7, 2025
eolivelli
left a comment
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.
LGTM
Let's commit the patch only once the CNDB side PR is reviewed and CI passes there
michaelsembwever
pushed a commit
that referenced
this pull request
Nov 17, 2025
…re-compiling regex patterns (#2104) riptano/cndb#13612 Summary This PR optimizes the Component.Type.fromRepresentation() method by pre-compiling regex patterns in the enum constructor instead of compiling them on every match operation. This improves performance for component type matching, which can occur frequently during SSTable operations. Changes Added pre-compiled Pattern field to Component.Type enum Patterns are now compiled once during enum initialization CUSTOM type correctly handles null pattern Updated matching logic in fromRepresentation() Changed from Pattern.matches() to reusing pre-compiled patterns Added null check with IllegalArgumentException for invalid input Made method package-private (was incorrectly public despite @VisibleForTesting) Added comprehensive unit tests
michaelsembwever
pushed a commit
that referenced
this pull request
Dec 9, 2025
…re-compiling regex patterns (#2104) riptano/cndb#13612 Summary This PR optimizes the Component.Type.fromRepresentation() method by pre-compiling regex patterns in the enum constructor instead of compiling them on every match operation. This improves performance for component type matching, which can occur frequently during SSTable operations. Changes Added pre-compiled Pattern field to Component.Type enum Patterns are now compiled once during enum initialization CUSTOM type correctly handles null pattern Updated matching logic in fromRepresentation() Changed from Pattern.matches() to reusing pre-compiled patterns Added null check with IllegalArgumentException for invalid input Made method package-private (was incorrectly public despite @VisibleForTesting) Added comprehensive unit tests
michaelsembwever
pushed a commit
that referenced
this pull request
Dec 9, 2025
…re-compiling regex patterns (#2104) riptano/cndb#13612 Summary This PR optimizes the Component.Type.fromRepresentation() method by pre-compiling regex patterns in the enum constructor instead of compiling them on every match operation. This improves performance for component type matching, which can occur frequently during SSTable operations. Changes Added pre-compiled Pattern field to Component.Type enum Patterns are now compiled once during enum initialization CUSTOM type correctly handles null pattern Updated matching logic in fromRepresentation() Changed from Pattern.matches() to reusing pre-compiled patterns Added null check with IllegalArgumentException for invalid input Made method package-private (was incorrectly public despite @VisibleForTesting) Added comprehensive unit tests
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



https://github.com/riptano/cndb/issues/13612
Summary
This PR optimizes the Component.Type.fromRepresentation() method by pre-compiling regex patterns in the enum constructor instead of compiling them on every match operation. This improves performance for component type matching, which can occur frequently during SSTable operations.
Changes
Added pre-compiled Pattern field to Component.Type enum
Patterns are now compiled once during enum initialization
CUSTOM type correctly handles null pattern
Updated matching logic in fromRepresentation()
Changed from Pattern.matches() to reusing pre-compiled patterns
Added null check with IllegalArgumentException for invalid input
Made method package-private (was incorrectly public despite @VisibleForTesting)
Added comprehensive unit tests
Test null input validation
Test empty string handling (returns CUSTOM as expected)
Existing test coverage maintained
Performance Impact
Eliminates repeated regex compilation overhead
Particularly beneficial for workloads with frequent component type lookups
Testing
All existing unit tests pass
Added testFromRepresentationNullInput() to verify precondition
Added testFromRepresentationEmptyString() to verify empty string behavior