Skip to content
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

Optimize Quantity.parse to avoid regex overhead #4992

Merged
merged 3 commits into from
Mar 28, 2023

Conversation

schlosna
Copy link
Contributor

@schlosna schlosna commented Mar 23, 2023

Description

Optimize Quantity.parse to avoid regex overhead. While reviewing some JFR profiles from a service using fabric8.io k8s client, I noticed some significant allocations and CPU time spent parsing quantities using regex from interacting with k8s APIs. We can avoid some of these overheads by simplifying the parsing to identify when and where to split quantity and units.

image
image
image

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Checklist

  • Code contributed by me aligns with current project license: Apache 2.0
  • I Added CHANGELOG entry regarding this change
  • I have implemented unit tests to cover my changes
  • I have added/updated the javadocs and other documentation accordingly
  • No new bugs, code smells, etc. in SonarCloud report
  • I tested my code in Kubernetes
  • I tested my code in OpenShift

Comment on lines +296 to +298
default:
//noinspection UnnecessaryContinue - satisfy Sonar
continue;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without this default case, Sonar flags this as a critical Add a default case to this switch. , though with the default case of continue IntelliJ then flags it as unnecessary. Defer to your preferences if you'd like an empty default case or if the comment suppressing IntelliJ warning is ok with you all.

Copy link
Member

Choose a reason for hiding this comment

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

Sonar false positives can be disabled by using a @SuppressWarnings annotation followed by the rule id e.g. @SuppressWarnings("java:S107")

Copy link
Contributor

@shawkins shawkins left a comment

Choose a reason for hiding this comment

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

LGTM

@schlosna
Copy link
Contributor Author

It looks like the Sonar Scanner / Sonar (pull_request) check is failing on JettyHttpClientTest>OkHttpClientTest.supportedResponseBodyTypes:197. I don't think this is related to this change, is this a known test flake?

Let me know if there's anything else you need to merge. Thanks!

@shawkins
Copy link
Contributor

I don't think this is related to this change, is this a known test flake?

It's definitely not related, but it's not a known test flake. Captured as #5002 - there does appear to be a timing issue with the jetty logic.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

96.8% 96.8% Coverage
0.0% 0.0% Duplication

Copy link
Member

@manusa manusa left a comment

Choose a reason for hiding this comment

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

LGTM, thx!

@manusa manusa added this to the 6.6.0 milestone Mar 28, 2023
@manusa manusa merged commit 3a4b4ae into fabric8io:master Mar 28, 2023
@schlosna schlosna deleted the ds/optimize-parse-quantity branch May 23, 2023 02:37
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.

5 participants