Reduce memory allocations when computing accessibilityLabel#44605
Closed
sparga wants to merge 2 commits intofacebook:mainfrom
Closed
Reduce memory allocations when computing accessibilityLabel#44605sparga wants to merge 2 commits intofacebook:mainfrom
sparga wants to merge 2 commits intofacebook:mainfrom
Conversation
Member
|
Thanks for contributing! I think getting the two implementations to match and returning nil when there is no label would be desired. |
9cc9c06 to
3e31585
Compare
Author
|
Sorry, it took me a while to address the feedback but I finally took the time to do it. |
javache
approved these changes
Dec 24, 2024
Contributor
|
@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Contributor
Collaborator
|
This pull request was successfully merged by @sparga in 74bdab8 When will my fix make it into a release? | How to file a pick request? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary:
While investigating the root cause of app hanging on older devices in Instruments, I noticed that the heaviest stack trace was pointing to
RCTRecursiveAccessibilityLabelin RCTView.m.Heaviest stack trace in Instruments
The profiling was done on an iPad (5th generation) running iOS 16.7.4. The app is text heavy which makes the issue more visible than in RNTester for instance.
Before
It turns out that
[NSMutableString stringWithString:@""]is initialized in every call of the recursion even though most of the time it's only used to check the length at the end and returnnil.My change only initialize the mutable string if it's going to be used. I applied the same logic to the equivalent Fabric component. It's a small change that improved the accessibility label generation by 60ms in my case.
Changelog:
[IOS] [CHANGED] - Reduce memory allocations when computing accessibilityLabel
Test Plan:
Running the same measurements after the change, computing the accessibility label is not the heaviest stack trace anymore. And the line by line tracing shows that
[NSMutableString stringWithString:@""]impact has been significantly reduced.After
I have been using this change in production thanks to a patch-package and it effectively improved the performances when navigating between screens.
I also tested in RNTester with and without Fabric. For both architectures, I made sure the return value of
RCTRecursiveAccessibilityLabel.Interestingly, when there is no label, the Fabric implementation returns an empty string while the
RCTView.mreturnsnil.I'm open to align both implementations to return
nilif you believe there is no underlying reason requiring the Fabric implementation to return an empty string.