Repository navigation
Commit 7230b63
authored
Skip copying the culling context in the differ when view culling is off
## Summary:
In its two per-child loops (slicing a node's children, and walking matched child pairs), the differ calls `CullingContext::adjustCullingContextIfNeeded` for every child and reads `ReactNativeFeatureFlags::enableViewCulling()` each time. Each call builds a `ShadowViewNodePair` with a copy of the child's `ShadowView` (props, state and event emitter `shared_ptr`s) and returns a new `CullingContext` (a `Rect` and a `Transform` with its operations vector). Without view culling, the result is always an unchanged copy of the parent's context.
View culling is off by default, so every commit pays for this on every child the differ visits. This change reads the flag once per call and, when culling is off, passes the parent's context to the children instead. With culling on, the same calls run in the same order as before. The other `adjustCullingContextIfNeeded` calls are in rarer paths (flattening, unflattening, deletions) and are left as they are.
I found this while profiling typing in a `TextInput` on Android: each keystroke commits a state update, and the differ walks the whole screen. On a low-end phone the copies were about 5% of the differ's time.
## Changelog:
[GENERAL] [CHANGED] - The differ no longer copies its view culling context for every child when view culling is off
## Test Plan:
- `yarn fantom` with the tester rebuilt from this change:
- `ScrollView-viewCulling-itest.js` (runs with `enableViewCulling:true`): 44 passed.
- `TextInput` suites 39 passed, `ScrollView` suites 86 passed, `Mounting-itest.js` 56 passed.
- Full suite: 3316 passed. The other failures are not related to this change: snapshot printing in my checkout's Jest setup (LogBox and `expect` snapshots), and the known flaky tester crash in one suite (`polyfillArrayES2023Methods-itest.js`), which passes on rerun.
- `clang-format` clean (`node scripts/clang-format.js --check`).
- **On a device.** RNTester release build on a Galaxy A16 (Android 16), one APK with both versions behind a local switch, typing into a `TextInput` on the TextInput example page for 12 s per run, call stacks sampled at 1 kHz, 5 rounds alternating old/new. JS thread samples spent in `adjustCullingContextIfNeeded` and the flag reads:
| | before | this PR |
|---|--:|--:|
| per 12 s run | 13 / 9 / 12 / 12 / 12 | 2 / 1 / 1 / 2 / 0 |
That is about 1.3–1.5% of the JS thread while typing (the differ itself is about 30% of it). Total differ time moves by more than that between runs, so I am not claiming more.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Differential Revision: D128599926
Pull Request resolved: #596771 parent 3feed51 commit 7230b63
2 files changed
Lines changed: 33 additions & 9 deletions
File tree
- packages/react-native/ReactCommon/react/renderer/mounting
- internal
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
897 | 898 | | |
898 | 899 | | |
899 | 900 | | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
900 | 904 | | |
901 | 905 | | |
902 | 906 | | |
| |||
946 | 950 | | |
947 | 951 | | |
948 | 952 | | |
949 | | - | |
950 | | - | |
951 | | - | |
952 | | - | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
953 | 967 | | |
954 | 968 | | |
955 | 969 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
144 | 145 | | |
145 | 146 | | |
146 | 147 | | |
| 148 | + | |
| 149 | + | |
147 | 150 | | |
148 | 151 | | |
149 | 152 | | |
150 | 153 | | |
151 | 154 | | |
152 | 155 | | |
153 | 156 | | |
154 | | - | |
| 157 | + | |
155 | 158 | | |
156 | 159 | | |
157 | 160 | | |
| |||
181 | 184 | | |
182 | 185 | | |
183 | 186 | | |
184 | | - | |
185 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
186 | 196 | | |
187 | 197 | | |
188 | 198 | | |
| |||
200 | 210 | | |
201 | 211 | | |
202 | 212 | | |
203 | | - | |
| 213 | + | |
204 | 214 | | |
205 | 215 | | |
206 | 216 | | |
| |||
209 | 219 | | |
210 | 220 | | |
211 | 221 | | |
212 | | - | |
| 222 | + | |
213 | 223 | | |
214 | 224 | | |
215 | 225 | | |
| |||
0 commit comments