Skip to content

Conversation

@lesnik2u
Copy link

@lesnik2u lesnik2u commented Nov 5, 2025

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

after before

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

@lesnik2u lesnik2u self-assigned this Nov 5, 2025
@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Checklist before you submit for review

  • This PR adheres to the Definition of Done
  • Make sure there is a PR in the CNDB project updating the Converged Cassandra version
  • Use NoSpamLogger for log lines that may appear frequently in the logs
  • Verify test results on Butler
  • Test coverage for new/modified code is > 80%
  • Proper code formatting
  • Proper title for each commit staring with the project-issue number, like CNDB-1234
  • Each commit has a meaningful description
  • Each commit is not very long and contains related changes
  • Renames, moves and reformatting are in distinct commits
  • All new files should contain the DataStax copyright header instead of the Apache License one

@lesnik2u lesnik2u marked this pull request as ready for review November 5, 2025 14:50
@lesnik2u lesnik2u marked this pull request as draft November 5, 2025 14:55
@lesnik2u lesnik2u marked this pull request as ready for review November 6, 2025 13:38
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 6, 2025

@cassci-bot
Copy link

✔️ Build ds-cassandra-pr-gate/PR-2104 approved by Butler


Approved by Butler
See build details here

Copy link

@eolivelli eolivelli left a 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

@lesnik2u lesnik2u merged commit d19ed6d into main Nov 10, 2025
496 checks passed
@lesnik2u lesnik2u deleted the CNDB-13162-pattern branch November 10, 2025 09:45
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants