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

Optimization pack 2 #78

Merged
merged 2 commits into from
Feb 25, 2024
Merged

Optimization pack 2 #78

merged 2 commits into from
Feb 25, 2024

Conversation

oswaldobapvicjr
Copy link
Owner

@oswaldobapvicjr oswaldobapvicjr commented Feb 24, 2024

Enhancement

This Pull Request introduces the following optimization:

Reduce time unit conversion overhead

The Counter class was originally designed so that the times collected by the Counter instances could be maintained in different TimeUnits as specified by the constructor Counter(Type, TimeUnit).

This flexibility comes with a cost: all units are converted during time-source fetching. However, in practice, only "nanoseconds" were used. Removing this feature means we no longer need intermediary time unit conversions. Now, the Counter class, by definition, will store amounts in nanoseconds, making the class cleaner and faster.

With this simplification, we also removed the "default time unit" setting that used to be applied when no other was specified.

NOTE: Elapsed times can still be converted normally using a TimingSession or a TimingSessionContainer (such as Stopwatch) but the units are stored only as nanoseconds at the Counter level.

Other minor improvements

  • SystemUtils class optimization:
    • Store a local reference for the ThreadMXBean instance, avoiding repeated lookups for this Managed Bean
  • Optimize counters map handling inside the TimingSession class:
    • Remove bad usage of Map.containsKey(String) which caused the same key to be searched twice during the getCounter(Type) operation
  • Extract a common method for some duplicate code found inside DurationUtils

@oswaldobapvicjr oswaldobapvicjr self-assigned this Feb 24, 2024
@oswaldobapvicjr oswaldobapvicjr added the enhancement New feature or request label Feb 24, 2024
Copy link

codecov bot commented Feb 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (2638e21) to head (002a48f).

Additional details and impacted files
@@              Coverage Diff              @@
##             master       #78      +/-   ##
=============================================
+ Coverage     99.51%   100.00%   +0.48%     
- Complexity      323       326       +3     
=============================================
  Files            21        21              
  Lines           832       831       -1     
  Branches         35        34       -1     
=============================================
+ Hits            828       831       +3     
+ Misses            1         0       -1     
+ Partials          3         0       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@oswaldobapvicjr oswaldobapvicjr merged commit e7f1939 into master Feb 25, 2024
6 checks passed
@oswaldobapvicjr oswaldobapvicjr deleted the issue/0078 branch February 25, 2024 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant