Skip to content

Commit

Permalink
Include animation duration when computing cost/complexity of Core Ani…
Browse files Browse the repository at this point in the history
…mation time remapping (#2381)
  • Loading branch information
calda authored Apr 15, 2024
1 parent 3af9055 commit 769b88d
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 5 deletions.
21 changes: 18 additions & 3 deletions Sources/Private/CoreAnimation/CoreAnimationLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -537,11 +537,26 @@ extension CoreAnimationLayer: RootAnimationLayer {
/// every frame of every animation. For very large animations with a huge number of layers,
/// this can be prohibitively expensive.
func validateReasonableNumberOfTimeRemappingLayers() throws {
let numberOfLayersWithTimeRemapping = numberOfLayersWithTimeRemapping
let numberOfFrames = Int(animation.framerate * animation.duration)
let totalCost = numberOfLayersWithTimeRemapping * numberOfFrames

/// Cap the cost / complexity of animations that use Core Animation time remapping.
/// - Short, simple animations perform well, but long and complex animations perform poorly.
/// - We count the total number of frames that will need to be manually interpolated, which is
/// the number of layers with time remapping enabled times the total number of frames.
/// - The cap is arbitrary, and is currently:
/// - 1000 layers for a one second animation at 60fp
/// - 500 layers for a two second animation at 60fps, etc
/// - All of the sample animations in the lottie-ios repo below this cap perform well.
/// If users report animations below this cap that perform poorly, we can lower the cap.
let maximumAllowedCost = 1000 * 60

try layerContext.compatibilityAssert(
numberOfLayersWithTimeRemapping < 500,
totalCost < maximumAllowedCost,
"""
This animation has a very large number of layers with time remapping (\(numberOfLayersWithTimeRemapping)),
so will perform poorly with the Core Animation rendering engine.
This animation has a very large number of layers with time remapping (\(numberOfLayersWithTimeRemapping) \
layers over \(numberOfFrames) frames) so will perform poorly with the Core Animation rendering engine.
""")
}

Expand Down
1 change: 1 addition & 0 deletions Tests/Samples/Issues/issue_2330.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Supports Core Animation engine
Does not support Core Animation engine. Encountered compatibility issues:
[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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Does not support Core Animation engine. Encountered compatibility issues:
[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.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Does not support Core Animation engine. Encountered compatibility issues:
[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.
[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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 769b88d

Please sign in to comment.