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

feat: improve update kits performance #118

Merged
merged 1 commit into from
Mar 23, 2022

Conversation

willpassidomo
Copy link
Contributor

@willpassidomo willpassidomo commented Mar 21, 2022

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 change

Since we are now parsing on a background thread, the updateKits() method became asynchronous, so we updated the signature to return a KitLoadedCallback instance. This was required to keep the kitsLoaded status change as well as queuing state changes in KitFrameworkWrapper accurate, otherwise, we would be dequeuing before kits might have been fully loaded

I also chose to move the dequeing update logic to KitFrameworkWrapper. With these changes it is difficult to tell, from KitManagerImpl, 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 from UploadHandler and once on ConfigManager#delayedStart(). I removed the latter instance since the former will have already taken place by the time it was called

Testing Plan

  • {explain how this has been tested, and what additional testing should be done}

Master Issue

@willpassidomo willpassidomo changed the title Feat/sqdsdks 2992 improve update kits feat: improve update kits performance Mar 21, 2022
@willpassidomo willpassidomo changed the base branch from main to development March 21, 2022 18:37
@willpassidomo willpassidomo reopened this Mar 21, 2022
@willpassidomo willpassidomo force-pushed the feat/SQDSDKS-2992-improve-update-kits branch from 159d64f to d11c30d Compare March 21, 2022 18:49
- cache parsed kit configuration instance so we do not need to re-parse the same settings on kit reloads
- move kit configuration parsing to a background thread
@willpassidomo willpassidomo force-pushed the feat/SQDSDKS-2992-improve-update-kits branch from d11c30d to 9da38b8 Compare March 22, 2022 16:45
@sonarcloud
Copy link

sonarcloud bot commented Mar 22, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@willpassidomo willpassidomo marked this pull request as ready for review March 22, 2022 18:03
@willpassidomo willpassidomo merged commit cb9e321 into development Mar 23, 2022
@willpassidomo willpassidomo deleted the feat/SQDSDKS-2992-improve-update-kits branch March 23, 2022 19:17
github-actions bot pushed a commit that referenced this pull request Mar 24, 2022
# [5.37.0](v5.36.2...v5.37.0) (2022-03-24)

### Bug Fixes

* Proguard keeps KitsLoadedCallback ([#119](#119)) ([e8cfd97](e8cfd97))

### Features

* improve kit loading performance ([#118](#118)) ([cb9e321](cb9e321))
@mparticle-automation
Copy link
Collaborator

🎉 This PR is included in version 5.37.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants