[iOS] Consider caching `accessibilityLabel` for RNGestureHandlerButton
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 53/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- ios, objective-c, react-native
- Lĩnh vực
- accessibility, mobile, performance
Hướng nghiên cứu
Start in the iOS implementation of RNGestureHandlerButton and inspect its accessibilityLabel getter and RNGHRecursiveAccessibilityLabel. The issue proposes caching the inferred label for the current main-queue turn; review how the button's view tree can change during that interval. Done means repeated accessibility queries reuse the label within a turn and still reflect the current tree on the next turn.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
While testing performance with iOS accessibility settings turned on (Voice Control), we found that the app becomes extremely laggy: scrolling and opening screens freeze for several seconds.
This comes from how Voice Control queries the accessibility tree.
- After new content mounts, it asks the app many times per second which element is focused. UIKit answers each request synchronously on the main thread by walking the whole view hierarchy. During that walk, React Native's Text (
RCTParagraphComponentView) runsisAccessibilityCoopted, which walks up through every ancestor of everyTextand readsaccessibilityLabelon any non-RN view, only to check that a label exists. - When the ancestor is an RNGH button with no explicit label, its getter (
RNGHRecursiveAccessibilityLabel) rebuilds the label from the button's whole subtree, creating a newNSAttributedStringfor everyTextinside it. A button with N texts therefore rebuilds its label N + 1 times per query, and this repeats for every mounted button on every query.
In our profiles (Time Profiler, iPhone 17 Pro, iOS 26.6.1), this accounted for ~3.3s of main-thread time plus ~2.3s spent building attributed strings on a busy screen.
React Native already knows this lookup is expensive and avoids it for its own views (facebook/react-native#50265):
} else if (![ancestor isKindOfClass:[RCTViewComponentView class]] && ancestor.accessibilityLabel) {
// Same as above, for UIView case. Cannot call this on RCTViewComponentView
// as it is recursive and quite expensive.
return NO;
}
RNGH can't benefit from this. RNGestureHandlerButtonComponentView is an RCTViewComponentView, but children are mounted inside the inner RNGestureHandlerButton, which is a UIControl. React Native reaches that control first and calls its expensive getter.
Therefore, we propose caching the inferred label for the current main-queue turn. An accessibility query runs synchronously on the main thread and the view tree can't change during it, so the label is built once per query instead of once per Text, and it is never stale. With this change, the time spent in the getter dropped by 82% (3,285ms → 593ms) and attributed-string building by 80% (2,259ms → 457ms):
@implementation RNGestureHandlerButton {
...
+ BOOL _isRecursiveAccessibilityLabelCached;
+ NSString *_cachedRecursiveAccessibilityLabel;
}
- (NSString *)accessibilityLabel
{
NSString *label = super.accessibilityLabel;
if (label) {
return label;
}
- return RNGHRecursiveAccessibilityLabel(self);
+ if (!_isRecursiveAccessibilityLabelCached) {
+ _cachedRecursiveAccessibilityLabel = RNGHRecursiveAccessibilityLabel(self);
+ _isRecursiveAccessibilityLabelCached = YES;
+ __weak RNGestureHandlerButton *weakSelf = self;
+ dispatch_async(dispatch_get_main_queue(), ^{
+ RNGestureHandlerButton *strongSelf = weakSelf;
+ if (strongSelf != nil) {
+ strongSelf->_isRecursiveAccessibilityLabelCached = NO;
+ strongSelf->_cachedRecursiveAccessibilityLabel = nil;
+ }
+ });
+ }
+ return _cachedRecursiveAccessibilityLabel;
}
Steps to reproduce
- On a physical iPhone, enable Voice Control (Settings → Accessibility → Voice Control). Simulators don't have this setting.
- Run the snippet below and scroll up and down.
- Scrolling stutters while new rows mount.
- For comparison, disable Voice Control and repeat: scrolling is smooth.
import { FlatList, Text, View } from 'react-native';
import { GestureHandlerRootView, Touchable } from 'react-native-gesture-handler';
const data = Array.from({ length: 80 }, (_, i) => i);
export default function App() {
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<FlatList
data={data}
keyExtractor={String}
renderItem={({ item }) => (
<Touchable onPress={() => {}} style={{ padding: 12 }}>
<View style={{ flexDirection: 'row', justifyContent: 'space-between' }}>
<View>
<Text>Item {item}</Text>
<Text>Subtitle {item}</Text>
</View>
<View>
<Text>123.45</Text>
<Text>+1.23%</Text>
</View>
</View>
</Touchable>
)}
/>
</GestureHandlerRootView>
);
}
A link to a Gist, an Expo Snack or a link to a repository based on this template that reproduces the bug.
Gesture Handler version
3.5.0
React Native version
0.86.3
Platforms
iOS
JavaScript runtime
None
Workflow
None
Build type
None
Device
Real device
Device model
No response
Acknowledgements
Yes
- Ngôn ngữ chính
- TypeScript
- Star
- 6.8k
- Fork
- 1.1k
- Merge trung bình
- 2 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 28
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của software-mansion/react-native-gesture-handler
-
GestureDetector should bubble touches if all gestures fail (or some other generalized solution)Đang mởMissing repro Platform: Android Platform: iOS
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 39/100
software-mansion/react-native-gesture-handler#4714 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Web] A pan that starts on a Pressable presses it when the mouse button is releasedCó thể đã có người làm @mokshupadhyay đã nhận 2 ngày trước. Đang mởPlatform: Web
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 57/100
software-mansion/react-native-gesture-handler#4713 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[iOS] Crash at app exit: static `_managers` map destroyed while `flushOperations` reads itCó thể đã có người làm @beqramo đã nhận 5 ngày trước. Đang mởMissing info Missing repro Platform: iOS Platform: MacOS
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 30/100
software-mansion/react-native-gesture-handler#4711 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[iOS][Fabric] Recognizer of a live handler stays on a recycled view and takes every drag on the component that reuses itCó thể đã có người làm @nihar777 đã nhận 6 ngày trước. Đang mởPlatform: iOS
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
software-mansion/react-native-gesture-handler#4710 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[iOS] Button press feedback invisible on quick taps when Reduce Motion is enabledCó thể đã có người làm @andreialecu đã nhận 8 ngày trước. Đang mởMissing info Platform: iOS Platform: MacOS
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
software-mansion/react-native-gesture-handler#4707 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của software-mansion/react-native-gesture-handler
Issue tương tự
-
agentic-workflows
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
opencollective/opencollective-frontend#12789 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Web download page shows a file as Completed when its download from S3 fails with an error responseĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
awslabs/visual-asset-management-system#2097 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
openwatersio/slackwater#591 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
compiler-explorer/compiler-explorer#9738 ·
Maintainer thường phản hồi trong vòng 2 ngày