Skip to content

Commit 539aa78

Browse files
nattb8claude
andcommitted
perf(audience-sample): improve scroll performance in sample app (SDK-314)
Add UsageHints.GroupTransform to both scroll view content containers so the renderer translates each subtree on the GPU rather than re-compositing every element on each scroll frame. Cap the log at 200 rows so the visual tree stays bounded as events accumulate. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5f37b32 commit 539aa78

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

examples/audience/Assets/SampleApp/Scripts/AudienceSample.UI.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ private static readonly (string TabId, string PanelId)[] Tabs =
3030

3131
private const int CollapseThreshold = 240;
3232
private const int StatusPollIntervalMs = 500;
33+
private const int MaxLogRows = 200;
3334
private const float NarrowBreakpointPx = 1024f;
3435
private const float PhoneBreakpointPx = 480f;
3536

@@ -236,6 +237,11 @@ private void BindElements()
236237
// scroller never engages.
237238
_logView.contentContainer.style.flexShrink = 0;
238239

240+
// Tell the renderer the log subtree moves as a unit when scrolled.
241+
// Without this hint Unity re-composites every row on each scroll
242+
// frame; with it the subtree is translated on the GPU instead.
243+
_logView.contentContainer.usageHints = UsageHints.GroupTransform;
244+
239245
_logCount = Require<Label>("log-count");
240246
}
241247

@@ -416,6 +422,7 @@ void Update()
416422
if (float.IsNaN(needed) || needed <= 0f) return;
417423
pageScroll.contentContainer.style.minHeight = needed;
418424
}
425+
pageScroll.contentContainer.usageHints = UsageHints.GroupTransform;
419426
controls.RegisterCallback<GeometryChangedEvent>(_ => Update());
420427
logCol.RegisterCallback<GeometryChangedEvent>(_ => Update());
421428
pageScroll.contentContainer.schedule.Execute(Update).StartingIn(0);
@@ -759,6 +766,12 @@ private void AppendLog(string label, string? body, LogLevel level, LogSource sou
759766

760767
var row = BuildLogRow(new LogEntry(DateTime.Now, label, body, level, source));
761768
_logView.Add(row);
769+
770+
// Keep the visual tree bounded so scroll performance doesn't degrade
771+
// as the log grows. Remove the oldest row when the cap is exceeded.
772+
while (_logView.contentContainer.childCount > MaxLogRows)
773+
_logView.contentContainer.RemoveAt(0);
774+
762775
_logCount.text = _logView.contentContainer.childCount.ToString(CultureInfo.InvariantCulture);
763776

764777
// contentContainer.flexShrink = 0 (set in BindElements) makes the

0 commit comments

Comments
 (0)