Skip to content

Conversation

@shawkins
Copy link
Collaborator

After expanding the micro benchmark to include warm-up, and a variety of comparison scenarios, it does appear there are a couple of improvements that can be made. This seems to be the optimal and most straight-forward.

It is about 45% faster than using parseLong, but that still may not be good enough to rely upon in github actions without warmup due to garbage collection and or cpu throttling.

Another reason, besides performance, to not use parseLong is that I believe the Kubernetes folks are allowing for the possiblity of arbitrary length resourceVersions.

cc @metacosm @csviri

@Copilot Copilot AI review requested due to automatic review settings October 23, 2025 11:52
@openshift-ci openshift-ci bot requested review from metacosm and xstefank October 23, 2025 11:52
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 PR refines the resource version comparison logic to improve both performance and correctness. The implementation is simplified to compare resource versions as numeric strings more efficiently, achieving approximately 45% performance improvement over the previous approach while maintaining proper validation.

Key Changes:

  • Extracted validation logic into a separate helper method for better code organization
  • Simplified comparison algorithm by first comparing lengths, then character-by-character when lengths match
  • Consolidated error messages to remove redundant "(1)" and "(2) suffixes

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +477 to 481
if (char1 == '0') {
if (i == 0) {
throw new NonComparableResourceVersionException(
"Non numeric characters in resource version (2): " + char2);
}
if (char1 == 0) {
comparison = -1;
} else if (comparison == 0) {
comparison = Character.compare(char1, char2);
"Resource version cannot begin with 0: " + v1);
}
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation logic incorrectly allows '0' characters at any position except the first. This means resource versions like '10', '20', '100' would be valid, but '101' would fail validation when it encounters the '0' at position 1. The condition should only validate the leading zero case, not reject all '0' characters.

Copilot uses AI. Check for mistakes.
@csviri csviri changed the title refining resource version comparison improve: refining resource version comparison Oct 23, 2025
@csviri csviri merged commit 3075f11 into operator-framework:next Oct 23, 2025
16 of 25 checks passed
@csviri
Copy link
Collaborator

csviri commented Oct 23, 2025

Sorry I did not mean to merge this yet, but since cannot easily undo, will stick with it

Copy link
Collaborator

@csviri csviri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

late LGTM

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