feat: improve update kits performance #118
Merged
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
This greatly improves performance for our updateKits() function, specifically with respect to main thread usage. We found that very large kit configurations result in significant periods of main thread usage. The problem occurs primarily during kit configuration parsing and occurs both when the kits are initially loaded and every time Consent State is update, every time the current MParticleUser changes, and every time Opt in/Opt out status is changed.
When kits are initially loaded, it is unavoidable that we need to parse the kit configuration. To avoid excessive main thread usage, this parsing now takes place on a dedicated background thread.
For the latter situations (Consent State, opt-in, and User change), we should not have to re-parse the kit configuration, since the kit configuration has not changed. To solve this, we will now retain references to the parsed
KitConfiguation
instances and reuse them.KitLoadedCallback
and KitManager#updateKits() signature changeSince we are now parsing on a background thread, the
updateKits()
method became asynchronous, so we updated the signature to return aKitLoadedCallback
instance. This was required to keep the kitsLoaded status change as well as queuing state changes inKitFrameworkWrapper
accurate, otherwise, we would be dequeuing before kits might have been fully loadedI also chose to move the dequeing update logic to
KitFrameworkWrapper
. With these changes it is difficult to tell, fromKitManagerImpl
, whether we are performing a kit reload before a config had been loaded (no cached config) or if we have loaded a bonified kit configuration. Regardless,KitFrameworkWrapper
seems like the more appropriate responsible class anyway to handle this since it is essentially the "manager of the KitManager"Remove ConfigManager#reloadKitConfig()
During testing I discovered that we are "reloading" any cached configuration twice, once when the
loadKitFramework()
call is made fromUploadHandler
and once onConfigManager#delayedStart()
. I removed the latter instance since the former will have already taken place by the time it was calledTesting Plan
Master Issue