Skip to content

Commit ce37b11

Browse files
authored
Merge pull request #559 from CommunityToolkit/dev/getrou/perf_fix
Update IsChildOf graph walk in LayersGraph.cs
2 parents e37426d + 209d27a commit ce37b11

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

source/Lottie/Loader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ await Task.Run(() =>
9090
LottieCompositionReader.Options.IgnoreMatchNames,
9191
out var readerIssues);
9292

93-
if (lottieComposition is not null)
93+
if (lottieComposition is not null && options.HasFlag(LottieVisualOptions.Optimize))
9494
{
9595
lottieComposition = LottieMergeOptimizer.Optimize(lottieComposition);
9696
}

source/LottieData/Optimization/LayersGraph.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ namespace CommunityToolkit.WinUI.Lottie.LottieData.Optimization
1111
/// <summary>
1212
/// Represents directed acyclic graph of layer groups.
1313
/// Node1 is child of Node2 iff they have time ranges that intersect and Node1 goes after Node2 in z-order.
14+
///
15+
/// +Z
16+
/// |---------------------------------------------------|
17+
/// |--Node1--|
18+
/// |---Node2---| Time -->
19+
/// |----Node3----|
20+
/// |---------------------------------------------------|
21+
/// -Z
22+
///
23+
/// In this example Node1 is a child of Node2, but not of Node3.
24+
/// Nodes can have multiple parents. Optimizations can be made to graphs that don't overlap in
25+
/// time, which is often the case when a single Lottie file contains multiple animations.
1426
/// </summary>
1527
#if PUBLIC_LottieData
1628
public
@@ -57,16 +69,16 @@ public bool IsChildOf(GraphNode node)
5769

5870
private bool IsChildOf(GraphNode node, HashSet<GraphNode> visited)
5971
{
60-
if (visited.Contains(node))
72+
if (visited.Contains(this))
6173
{
6274
return false;
6375
}
6476

65-
visited.Add(node);
77+
visited.Add(this);
6678

6779
foreach (var parent in Parents)
6880
{
69-
if (parent.Equals(node) || parent.IsChildOf(node))
81+
if (parent.Equals(node) || parent.IsChildOf(node, visited))
7082
{
7183
return true;
7284
}

0 commit comments

Comments
 (0)