Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include animation duration when computing cost/complexity of time remapping #2381

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading