-
Notifications
You must be signed in to change notification settings - Fork 592
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
Fireperf: [Startup improvement] lazy initialize expensive objects in GaugeManager #3011
Conversation
Coverage ReportAffected SDKs
Test Logs
NotesHTML coverage reports can be produced locally with Head commit (396a33c0) is created by Prow via merging commits: 79975f0 3aa1bb7. |
Binary Size ReportAffected SDKs
Test Logs
NotesHead commit (396a33c0) is created by Prow via merging commits: 79975f0 3aa1bb7. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work!
I think at this point, it will work if Cpu and Memory gauge collectors are not singletons. The point of making these two being singletons is to make sure there is only one instance of each in the environment if other classes want to use them. |
Honestly, the only reason they are singletons is not to have redundant collectors of such metrics. But, given the fact they are being used only by the gauge manager, they don't have to be singleton. I would prefer for us to remove them to be singletons. Do you know the complexity in making them non-singleton? |
It should be quick and easy, unless it breaks a lot of tests which I don't expect to happen. Just updated PR with removal of singleton |
/test smoke-tests |
1 similar comment
/test smoke-tests |
As per b/201001743, the goal is to "Optimize SessionManager getInstance() to check of session enabled flags before initializing gaugeManager".
Why we can't lazy initialize GaugeManager
Currently no matter if verbose session is turned on or off, a method in
GaugeManager
is guaranteed to be called inFirebasePerfProvider.attachInfo()
. Specifically,FirebasePerfProvider.attachInfo()
callsSessionManager.updatePerfSession
which callsSessionManager.startOrStopCollectingGauges
, which then checks if verbose session is on, if yes it callsgaugeManager. startCollectingGauges
, otherwise it callsgaugeManager.stopCollectingGauges
.Therefore
GaugeManager
must be initialized.But we can lazy initialize expensive objects in GaugeManager
There are 3 relatively expensive objects in
GaugeManager
that are not used when verbose session is off, but they are currently eagerly initialized. This PR just makes these 3 objects lazy, using a helper class from firebase-components.Additional optimization
Also swapped a
String.replaceAll
toString.replace
for very slight improvement.Other changes
Changed CpuGaugeCollector and MemoryGaugeCollector from singletons to normal objects (since they are only owned by GaugeManager which is a singleton already)