Skip to content

Commit 769b88d

Browse files
authored
Include animation duration when computing cost/complexity of Core Animation time remapping (#2381)
1 parent 3af9055 commit 769b88d

15 files changed

+24
-5
lines changed

Sources/Private/CoreAnimation/CoreAnimationLayer.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,26 @@ extension CoreAnimationLayer: RootAnimationLayer {
537537
/// every frame of every animation. For very large animations with a huge number of layers,
538538
/// this can be prohibitively expensive.
539539
func validateReasonableNumberOfTimeRemappingLayers() throws {
540+
let numberOfLayersWithTimeRemapping = numberOfLayersWithTimeRemapping
541+
let numberOfFrames = Int(animation.framerate * animation.duration)
542+
let totalCost = numberOfLayersWithTimeRemapping * numberOfFrames
543+
544+
/// Cap the cost / complexity of animations that use Core Animation time remapping.
545+
/// - Short, simple animations perform well, but long and complex animations perform poorly.
546+
/// - We count the total number of frames that will need to be manually interpolated, which is
547+
/// the number of layers with time remapping enabled times the total number of frames.
548+
/// - The cap is arbitrary, and is currently:
549+
/// - 1000 layers for a one second animation at 60fp
550+
/// - 500 layers for a two second animation at 60fps, etc
551+
/// - All of the sample animations in the lottie-ios repo below this cap perform well.
552+
/// If users report animations below this cap that perform poorly, we can lower the cap.
553+
let maximumAllowedCost = 1000 * 60
554+
540555
try layerContext.compatibilityAssert(
541-
numberOfLayersWithTimeRemapping < 500,
556+
totalCost < maximumAllowedCost,
542557
"""
543-
This animation has a very large number of layers with time remapping (\(numberOfLayersWithTimeRemapping)),
544-
so will perform poorly with the Core Animation rendering engine.
558+
This animation has a very large number of layers with time remapping (\(numberOfLayersWithTimeRemapping) \
559+
layers over \(numberOfFrames) frames) so will perform poorly with the Core Animation rendering engine.
545560
""")
546561
}
547562

Tests/Samples/Issues/issue_2330.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Supports Core Animation engine
1+
Does not support Core Animation engine. Encountered compatibility issues:
2+
[root layer] This animation has a very large number of layers with time remapping (289 layers over 360 frames) so will perform poorly with the Core Animation rendering engine.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Does not support Core Animation engine. Encountered compatibility issues:
2+
[root layer] This animation has a very large number of layers with time remapping (406 layers over 193 frames) so will perform poorly with the Core Animation rendering engine.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Does not support Core Animation engine. Encountered compatibility issues:
2-
[root layer] This animation has a very large number of layers with time remapping (3670), so will perform poorly with the Core Animation rendering engine.
2+
[root layer] This animation has a very large number of layers with time remapping (3670 layers over 1001 frames) so will perform poorly with the Core Animation rendering engine.
70.8 KB
Loading
71.1 KB
Loading
80.8 KB
Loading
76 KB
Loading
43.9 KB
Loading

0 commit comments

Comments
 (0)