Skip to content

Commit a3c42ed

Browse files
andreakarashoclaude
andcommitted
Cull off-screen children in scroll containers
Skip render command generation for elements whose bounding box falls entirely outside their parent scroll container's clip bounds, reducing render commands for large scrollable content. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 49ff2b7 commit a3c42ed

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

src/Clay/Core/ClayContext.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,14 +1111,24 @@ private void GenerateRenderCommandsRecursive(int elementIndex, short zIndex, Bou
11111111

11121112
var boundingBox = hashItem.BoundingBox;
11131113

1114-
// Culling
1114+
// Culling against viewport
11151115
if (!CullingDisabled)
11161116
{
11171117
if (boundingBox.Right < 0 || boundingBox.Bottom < 0 ||
11181118
boundingBox.X > LayoutDimensions.Width || boundingBox.Y > LayoutDimensions.Height)
11191119
{
11201120
return;
11211121
}
1122+
1123+
// Culling against scroll container clip bounds
1124+
if (hasClip)
1125+
{
1126+
if (boundingBox.Right < clipBounds.X || boundingBox.Bottom < clipBounds.Y ||
1127+
boundingBox.X > clipBounds.Right || boundingBox.Y > clipBounds.Bottom)
1128+
{
1129+
return;
1130+
}
1131+
}
11221132
}
11231133

11241134
// Find configs
@@ -1187,6 +1197,17 @@ private void GenerateRenderCommandsRecursive(int elementIndex, short zIndex, Bou
11871197
childHashItem.HasClipBounds = childHasClip;
11881198
childHashItem.ClipBounds = childClip;
11891199

1200+
// Cull text elements outside scroll container bounds
1201+
if (!CullingDisabled && childHasClip)
1202+
{
1203+
var childBox = childHashItem.BoundingBox;
1204+
if (childBox.Right < childClip.X || childBox.Bottom < childClip.Y ||
1205+
childBox.X > childClip.Right || childBox.Y > childClip.Bottom)
1206+
{
1207+
continue;
1208+
}
1209+
}
1210+
11901211
int textConfigIndex = FindConfigIndex(ref child, ElementConfigType.Text);
11911212
if (textConfigIndex < 0) continue;
11921213

0 commit comments

Comments
 (0)