Skip to content

Conversation

@DomGarguilo
Copy link
Member

Adds changes to several files that:

  • refactors elapsed-time tracking code to use Timer and/or Duration instead of raw System.nanoTime
    • improved safety (harder to make mistakes with Timer vs nanoTime)
    • stronger and more dynamic type Duration vs long

@DomGarguilo DomGarguilo self-assigned this Jan 7, 2026
@DomGarguilo DomGarguilo added this to the 4.0.0 milestone Jan 7, 2026
Copy link
Contributor

@dlmarion dlmarion left a comment

Choose a reason for hiding this comment

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

Made a couple of comments about using Duration.dividedBy and Duration.multipliedBy to avoid extra object creation instead of doing those operations on primitives.

long currentNanos = System.nanoTime();
if ((currentNanos - lastRun) >= threshold) {
Duration threshold = Duration.ofMillis(maxAgeMillis.getAsLong() / 2);
if (threshold.compareTo(minInterval) < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Guava has Comparators.min and Comparators.max that could be used like the existing code uses Math.min and Math.max. These changes are fine though, just pointing those out in case you were not aware.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing that out, I did not know of those. As I was writing this code I was wondering why there wasn't an equivalent for Duration variables but never looked into it.

Added in 17dd12d

@DomGarguilo DomGarguilo merged commit 15e9001 into apache:main Jan 9, 2026
8 checks passed
@DomGarguilo DomGarguilo deleted the improveTimingCode branch January 9, 2026 15:07
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.

3 participants