Commit ec4bbe3
committed
perf(mobile): cache initial SkPath in usePathTransition
`usePathTransition` was calling `Skia.Path.MakeFromSVGString` on every
render to compute `initialSkiaPath`, but the result is only ever consumed
as the initial value of the four `useSharedValue` calls below it. Since
`useSharedValue` ignores its argument on every render after the first,
every later parse was discarded.
Switch to a `useState` lazy initializer so the parse runs exactly once per
hook instance.
In an Android prod CPU trace (1:03 capture), this hot path accounted for
~64% of all `MakeFromSVGString` self-time (~350ms over the trace) across
`AnimatedPath` and `DottedArea` chart renders. `useState` is used
rather than `useMemo` because `useMemo` is documented as a perf hint that
React may discard, and any realistic dependency array would either fail the
exhaustive-deps lint rule (`[]`) or re-parse on every `currentPath` change
while the shared-value initializers continue to ignore the new result.1 parent fb3cf07 commit ec4bbe3
1 file changed
Lines changed: 16 additions & 3 deletions
Lines changed: 16 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
268 | | - | |
269 | | - | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
270 | 283 | | |
271 | 284 | | |
272 | 285 | | |
| |||
0 commit comments