Move decorating events with mutable device info to a background thread #214
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.
Description
This PR is related to improving performance of
TracksClient#track
method. This is crucial for performance of projects using this library - this method is called in numerous places, very often on the main thread. Internally we discussed and measure impact: paqN3M-18i-p2Fix
I moved execution of the longest method,
DeviceInformation#getMutableDeviceInfo
, to a thread that is responsible for moving events to local database. As a result,getMutableDeviceInfo
is executed a few milliseconds later than previously, but in reality it shouldn't affect business value that we gain from these properties.Test
Performance testing
I've introduced
benchmark
module to perform these tests. I don't add CI check of any kind, as it's not trivial when it comes to performance benchmarking and requires rather a solid setup which holds results from many previous executions. (https://medium.com/androiddevelopers/fighting-regressions-with-benchmarks-in-ci-6ea9a14b5c71).basicTrackMethod()
on a real devicegit revert 82f903cf53b3cfcc8f8af5d81e7e1842029943af
basicTrackMethod()
on a real device againValidation testing
In this test, we want only to validate if "mutable device info" are still updated.
5.0.0
woocommerce/woocommerce-android#11416 is not yet merged, please use it as a base as it addresses breaking changes introduced with Tracks 5.0.0 release.214-5c57d4048541a07f1e7b8aa011366e6844e71aee
)https://public-api.wordpress.com/rest/v1.1/tracks/record
withcommonProps
array anddevice_info_device_orientation
in it. Verify the value was correct.device_info_device_orientation
.Screenshots
Those are from my performance tests. They show median execution time over multiple executions.
Before
After