[opt] Use UILabel for stats overlay #671
Open
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.
As part of a general performance investigation, I found out that rendering the stats overlay was taking up to 20ms on my ATV 4K 1st Gen. This hangs the main thread long enough that the next displayLinkCallback is missed and results in skipped frames. A snapshot from a profile below shows a spike where the main thread was saturated due to activity related to
updateOverlayText.Our goal here is to reduce the time spent drawing the stats overlay. To do this, we switch the overlay from a UITextView to a UILabel. I am a complete novice at iOS, I just tried this because the UILabel seemed like a simpler solution for rendering a simple stats overlay. However, this did seem to improve the rendering times by quite a bit. On the same device, I'm seeing
updateOverlayTexttypically take only around 3ms now, down from 20ms. This has removed the visible frame skips that previously happened with the stats overlay is displayed.As part of this, also took another stab at styling the overlay since the default UILabel was pretty ugly. Added a bit of margin at the top, increased opacity slightly, and increased font weight. I think the new label is much more legible but you can still see through to the content if you need to.
Screenshot of the new label