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

Optimize PlayerPrefs event ID scanning when sending event batches #152

Merged
merged 3 commits into from
Dec 22, 2022
Merged

Optimize PlayerPrefs event ID scanning when sending event batches #152

merged 3 commits into from
Dec 22, 2022

Conversation

Kevinsomnia
Copy link
Contributor

This PR aims to fix performance issues when sending batches of events with high auto-increment IDs.

The performance issue stems from many string concatenations ("Event" + dataIndex.ToString()) and scanning PlayerPrefs for every ID between 0 and the next ID. This leads to a massive amount of GC allocations. The attached image is a snapshot of the Unity profiler which shows the issue in an extreme case: many events were sent throughout many app sessions.

image

The solution to this is to reset the auto-increment ID to 0 after sending all batches successfully (I determine this by checking dataIndex == maxIndex when deleting data). I'm assuming that this ID is only used for local storage purposes to keep track of unsuccessful batches and nothing else.

The alternative fix is to store the starting index so the ID scan doesn't have to start from index 0 every time it sends out a batch of events. The starting index can be determined as the lowest event index that wasn't sent yet.

Either method should mitigate/solve the issue, but we would want to at least keep the resetting the ID to 0 fix since it has less complexity.

@lourd
Copy link

lourd commented Sep 30, 2022

Tagging @zihejia and @jaredmixpanel as a request for review 🙏

@lourd
Copy link

lourd commented Nov 18, 2022

Hey @zihejia and @jaredmixpanel, sorry to bug you again. Can one of you please take a look at this PR and #153? 🙏

Copy link
Contributor

@zihejia zihejia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much!

@zihejia zihejia merged commit 9914a27 into mixpanel:master Dec 22, 2022
@Kevinsomnia Kevinsomnia deleted the improve-playerpref-perf branch January 25, 2023 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants