Skip to content

Refactor SlowRenderingDetectorImpl so that it's thread-safe #361

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

Merged
merged 1 commit into from
Sep 26, 2022

Conversation

mateuszrzeszutek
Copy link

Fixes #359

Removed the FrameMetricsAggregator, because it kept internal state that was not subject to any sort of synchronization whatsoever, and was accessed from multiple threads in an unsafe way. I refactored (simplified perhaps?) SlowRenderingDetectorImpl so that it uses FrameMetrics directly -- which, what's interesting, will allow us to collect per-activity metrics in the future, if we wish to do so.

@mateuszrzeszutek mateuszrzeszutek requested review from a team as code owners September 23, 2022 11:08
@mateuszrzeszutek mateuszrzeszutek changed the title Refactor SlowRenderingDetectorImpl so that it's thread-safe Refactor SlowRenderingDetectorImpl so that it's thread-safe Sep 23, 2022
@breedx-splk
Copy link
Contributor

Removed the FrameMetricsAggregator, because it kept internal state that was not subject to any sort of synchronization whatsoever, and was accessed from multiple threads in an unsafe way.

This is interesting because every usage of the frameMetrics instance within SlowRenderingDetectorImpl was definitely guarded by the lock, so I'm curious about where you observed unsafe accesses? Maybe you were thinking about the lack of coordination between the internal synchronization and our usage of it?

Copy link
Contributor

@breedx-splk breedx-splk left a comment

Choose a reason for hiding this comment

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

It makes me a little nervous to kinda reimplement some of what already exists in the guts of the platform sdk class FrameMetricsAggregator and how this could be impacted in the future. However, I do appreciate the sensitivity to thread-safety and a desire to make that better.

Aside from the reimplementation, I don't see anything to stop this change (but I would still like to better understand where the original thread safety concern came from). In the interest in getting the RC build out, let's go with this.

@breedx-splk breedx-splk merged commit c6bbbf4 into main Sep 26, 2022
@breedx-splk breedx-splk deleted the refactor-slow-rendering-detector branch September 26, 2022 16:57
@mateuszrzeszutek
Copy link
Author

(but I would still like to better understand where the original thread safety concern came from).

FrameMetricsAggregator internally started a thread (a HandlerThread for running the frame metrics listener) that modified the SparseIntArray[] metrics field without any sort of synchronization. So, while we were synchronizing all the reads in our own, the writes happening in the core library were completely unguarded.

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

Successfully merging this pull request may close these issues.

Fatal Exception: java.lang.ArrayIndexOutOfBoundsException: length=0; index=3
2 participants