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
Case 1340464 - remove GC allocation every frame on Android #101
Conversation
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.
Nothing out of the ordinary noticed when using the app for an extensive amount of time while monitoring the memory consumption and the behavior of the application.
{ | ||
s_ReceivedNotificationList.AddRange(s_ReceivedNotificationQueue); | ||
s_ReceivedNotificationQueue.Clear(); | ||
if (m_ReceivedNotificationQueue.Count == 0) |
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.
This feels fragile, for this code to work correctly, m_ReceivedNotificationList has to be empty, when the switch occurs. If it's not empty then out of order processing of notifications is possible. Only by looking at the whole file I understand that m_ReceivedNotificationList is empty when this switch occurs, but still if in the future someone will mess with m_ReceivedNotificationList, it will be easy to miss this place
Consider adding a safeguard
if (m_ReceivedNotificationList.Count != 0)
throw new Exception(..)
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.
If it's not empty, it means there are leftover notifications from last processing which shouldn't happen. Actually, this code still has a bug where this could happen (in case of exception), but that's addressed in different PR. When such leftovers happen, you get callbacks called again for the same notification next frame, most likely leading to the same exception again and postponing the same issue to the next frame etc. This change would scramble the ordering, but you'd still get bombarded with callbacks every frame when this happens.
Throwing exception like you propose would prevent callbacks from being called with logging about a bug. IMO, not throwing exception gives a clearer indication of bug (but it doesn't log the exact issue).
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.
"clearer indication of bug" - really? :) it's really not that apparent, especially for a green user. Well, if you're a fan of hidden bugs, so be it :)
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.
It's for sure clearer in our test project, reducing chances of us releasing a bug :)
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.
Waiting for reply
## [1.4.3] - 2022-04-15 ### Fixes: - [Android] [issue 101](Unity-Technologies/com.unity.mobile.notifications#101) Fix GC allocation every frame. - [1360115](https://issuetracker.unity3d.com/issues/mobile-notifications-project-settings-window-loses-focus-when-clicking-on-any-category-while-mobile-notifications-pane-is-open) Fixed focus loss when trying to switching from notifications settings. - [Android] [case 1376849] Fixed receivers needs to be marked as exported in manifest file, disable exact alarms on Android 12 because they require special permissions. - [iOS] [1375744](https://issuetracker.unity3d.com/issues/ios-app-freezes-slash-crashes-when-both-mobile-notifications-and-firebase-are-used) Fixed application startup hang when application uses Unity notifications or Firebase. - [iOS] [case 1382960] Handle numeric data in UserInfo. - [iOS] Correctly handle boolean values in UserInfo, previously boolean values were detected as numbers and get parsed as 1 or 0, now they will be correctly handled as 'true' and 'false'.
Improve Android implementation to be more performance and not make GC allocation every frame.
Changes:
To QA: try to break it (flood notifications).