Skip to content

Commit

Permalink
Fix performance test flakiness by reducing memory usage (airbnb#1679)
Browse files Browse the repository at this point in the history
  • Loading branch information
calda authored and Igor Moroz committed May 22, 2024
1 parent 7d5c87a commit c594a50
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 84 deletions.
69 changes: 3 additions & 66 deletions Lottie.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,13 @@
"version": "0.7.0"
}
},
{
"package": "SourceKitten",
"repositoryURL": "https://github.com/jpsim/SourceKitten.git",
"state": {
"branch": null,
"revision": "817dfa6f2e09b0476f3a6c9dbc035991f02f0241",
"version": "0.32.0"
}
},
{
"package": "AirbnbSwift",
"repositoryURL": "https://github.com/airbnb/swift",
"state": {
"branch": "master",
"revision": "b844956fd69f05e550038469a5d498462176f87a",
"version": null
"branch": null,
"revision": "1bf961396cc9c690db37936bfbdc8b5f29e844af",
"version": "1.0.1"
}
},
{
Expand All @@ -54,60 +45,6 @@
"revision": "88f6e2c0afe04221fcfb1601a2ecaad83115a05f",
"version": null
}
},
{
"package": "SwiftSyntax",
"repositoryURL": "https://github.com/apple/swift-syntax.git",
"state": {
"branch": null,
"revision": "0b6c22b97f8e9320bca62e82cdbee601cf37ad3f",
"version": "0.50600.1"
}
},
{
"package": "SwiftFormat",
"repositoryURL": "https://github.com/calda/SwiftFormat",
"state": {
"branch": null,
"revision": "2a9ed335450d3b3f66b2699d65124b9089195f5d",
"version": "0.49.11-beta-2"
}
},
{
"package": "SwiftLint",
"repositoryURL": "https://github.com/realm/SwiftLint",
"state": {
"branch": "e497f1f",
"revision": "e497f1f5b161af96ba439049d21970c6204d06c6",
"version": null
}
},
{
"package": "SwiftyTextTable",
"repositoryURL": "https://github.com/scottrhoyt/SwiftyTextTable.git",
"state": {
"branch": null,
"revision": "c6df6cf533d120716bff38f8ff9885e1ce2a4ac3",
"version": "0.9.0"
}
},
{
"package": "SWXMLHash",
"repositoryURL": "https://github.com/drmohundro/SWXMLHash.git",
"state": {
"branch": null,
"revision": "6469881a3f30417c5bb02404ea4b69207f297592",
"version": "6.0.0"
}
},
{
"package": "Yams",
"repositoryURL": "https://github.com/jpsim/Yams.git",
"state": {
"branch": null,
"revision": "9ff1cc9327586db4e0c8f46f064b6a82ec1566fa",
"version": "4.0.6"
}
}
]
},
Expand Down
35 changes: 17 additions & 18 deletions Tests/PerformanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,15 @@ final class PerformanceTests: XCTestCase {
{
let engineAPerformance = measurePerformance {
for _ in 0..<iterations {
// Each animation setup needs to be wrapped in its own `CATransaction`
// in order for the layers to be deallocated immediately. Otherwise
// the layers aren't deallocated until the end of the test run,
// which causes memory usage to grow unbounded.
CATransaction.begin()
let animationView = setupAnimationView(with: animation, configuration: .init(renderingEngine: engineA))
// Call `display()` on the layer to make sure any pending setup occurs immediately
animationView.animationLayer!.display()
CATransaction.commit()
setUpAndTearDownAnimationView(with: animation, configuration: .init(renderingEngine: engineA))
}
}

LottieLogger.shared.info("\(engineA) engine took \(engineAPerformance) seconds")

let engineBPerformance = measurePerformance {
for _ in 0..<iterations {
// Each animation setup needs to be wrapped in its own `CATransaction`
// in order for the layers to be deallocated immediately. Otherwise
// the layers aren't deallocated until the end of the test run,
// which causes memory usage to grow unbounded.
CATransaction.begin()
let animationView = setupAnimationView(with: animation, configuration: .init(renderingEngine: engineB))
// Call `display()` on the layer to make sure any pending setup occurs immediately
animationView.animationLayer!.display()
CATransaction.commit()
setUpAndTearDownAnimationView(with: animation, configuration: .init(renderingEngine: engineB))
}
}

Expand All @@ -141,6 +125,21 @@ final class PerformanceTests: XCTestCase {
return ratio
}

private func setUpAndTearDownAnimationView(with animation: Animation, configuration: LottieConfiguration) {
// Each animation setup needs to be wrapped in its own `CATransaction`
// in order for the layers to be deallocated immediately. Otherwise
// the layers aren't deallocated until the end of the test run,
// which causes memory usage to grow unbounded.
CATransaction.begin()
let animationView = setupAnimationView(with: animation, configuration: configuration)
// Call `display()` on the layer to make sure any pending setup occurs immediately
animationView.animationLayer!.display()
CATransaction.commit()

/// The view / layer is deallocated when the transaction is flushed
CATransaction.flush()
}

/// Compares performance of scrubbing the given animation with both the Main Thread and Core Animation engine,
/// and returns the ratio of how much slower the Core Animation is than the Main Thread engine
private func compareEngineScrubbingPerformance(for animation: Animation, iterations: Int) -> Double {
Expand Down

0 comments on commit c594a50

Please sign in to comment.