Use singleton for null telemetry objects in NullTelemetryFactory #1188
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
While testing our application for regressions in performance after adopting aws-advanced-jdbc-wrapper we found a lot of useless allocations from the NullTelemetryFactory [1].
[1]![Screenshot 2024-11-12 131311](https://private-user-images.githubusercontent.com/323497/385446898-d4f95f91-ee70-4161-9c49-5fa44ce76001.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NzA4MjUsIm5iZiI6MTczOTU3MDUyNSwicGF0aCI6Ii8zMjM0OTcvMzg1NDQ2ODk4LWQ0Zjk1ZjkxLWVlNzAtNDE2MS05YzQ5LTVmYTQ0Y2U3NjAwMS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE0JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxNFQyMjAyMDVaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0wZjE3N2ZlMWNmMTFmZTFmMDNkMGVhMWYxMDRhMjFiNTc1NzYyODU5ZTQwYjlhMmZjYTFlMmY4ZjUwMmI0N2RjJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.b72utFBK7NXqxsqYwQUZdB9GZVkn4cWmGrfjBGxv3e8)
Description
Refactored NullTelemetryFactory to use a singleton instance for NullTelemetryContext, TelemetryCounter, and TelemetryGauge, eliminating repeated object creation and reducing memory allocations.
I also considered using a caching approach but opted for the singleton pattern to further simplify the code and minimize memory churn. I verified software.amazon.jdbc.util.telemetry.NullTelemetryContext#getName is not used in any code paths.
Additional Reviewers
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.