Repository navigation
Commit 98e424c
authored
Reuse IntersectionObserver target ancestry (#60311)
Summary:
## Context
Explicit-root intersection updates resolve target-to-root ancestry even after resolving the target-to-surface path. This repeats allocations, parent-family locking, and sibling searches. Implicit roots also copy an ancestor list that can be reused directly.
## Changes
Derive the explicit-root path from the already resolved target ancestry after verifying root membership, and pass the existing list directly for implicit roots. Preserve clipping and detached/non-ancestor behavior. Add a public root-membership integration case and evaluate deep implicit/explicit roots using the shared benchmark-only baseline; this diff adds no benchmark code.
## Benchmark results
Optimized Fantom (native + Hermes bytecode), headless Linux, same CPU affinity. The benchmark-only baseline and final stack use the same base containing landed scrollMargin support. Values are median CPU time per complete invocation from the current runs; setup/assertions are outside timed work, and scaling cases have 100 measured invocations. These are workload-specific measurements, not isolated profiler timings or app-wide speedups.
| Benchmark | Baseline CPU | Current CPU | CPU reduction |
| --- | --- | --- | --- |
| `Scroll 100 targets, depth 40, 1 thresholds, implicit root` | 38.032 ms | 38.851 ms | -2.2% (within noise) |
| `Scroll 100 targets, depth 40, 1 thresholds, explicit root` | 46.293 ms | 40.505 ms | 12.5% |
The ancestry cases use one threshold and emit no callbacks during timed updates. Times include mounting; the small implicit-root difference is within run-to-run variation. Clipping and scrollMargin semantics are unchanged.
Changelog:
[General][Changed] - Reduce IntersectionObserver ancestor traversal overhead
Reviewed By: javache
Differential Revision: D134250309
Pull Request resolved: #603111 parent 5279b1b commit 98e424c
2 files changed
Lines changed: 55 additions & 4 deletions
File tree
- packages/react-native
- ReactCommon/react/renderer/observers/intersection
- src/private/webapis/intersectionobserver/__tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
280 | 281 | | |
281 | 282 | | |
282 | 283 | | |
283 | | - | |
284 | | - | |
285 | | - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
286 | 292 | | |
287 | 293 | | |
288 | 294 | | |
289 | 295 | | |
290 | 296 | | |
291 | | - | |
| 297 | + | |
292 | 298 | | |
293 | 299 | | |
294 | 300 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5195 | 5195 | | |
5196 | 5196 | | |
5197 | 5197 | | |
| 5198 | + | |
| 5199 | + | |
| 5200 | + | |
| 5201 | + | |
| 5202 | + | |
| 5203 | + | |
| 5204 | + | |
| 5205 | + | |
| 5206 | + | |
| 5207 | + | |
| 5208 | + | |
| 5209 | + | |
| 5210 | + | |
| 5211 | + | |
| 5212 | + | |
| 5213 | + | |
| 5214 | + | |
| 5215 | + | |
| 5216 | + | |
| 5217 | + | |
| 5218 | + | |
| 5219 | + | |
| 5220 | + | |
| 5221 | + | |
| 5222 | + | |
| 5223 | + | |
| 5224 | + | |
| 5225 | + | |
| 5226 | + | |
| 5227 | + | |
| 5228 | + | |
| 5229 | + | |
| 5230 | + | |
| 5231 | + | |
| 5232 | + | |
| 5233 | + | |
| 5234 | + | |
| 5235 | + | |
| 5236 | + | |
| 5237 | + | |
| 5238 | + | |
| 5239 | + | |
| 5240 | + | |
| 5241 | + | |
| 5242 | + | |
5198 | 5243 | | |
5199 | 5244 | | |
5200 | 5245 | | |
| |||
0 commit comments