Replace @blocks.each with while loop in If render — avoids block proc allocation per render\n\nResult: {"status":"keep","combined_µs":3496,"parse_µs":2356,"render_µs":1140,"allocations":24530}

This commit is contained in:
Tobi Lutke
2026-03-12 17:31:41 -04:00
parent db348e0dac
commit b195d09212
2 changed files with 6 additions and 2 deletions
+5 -2
View File
@@ -51,14 +51,17 @@ module Liquid
end
def render_to_output_buffer(context, output)
@blocks.each do |block|
idx = 0
blocks = @blocks
while idx < blocks.length
block = blocks[idx]
result = block.evaluate(context)
# Inline to_liquid_value fast path — respond_to? check is rarely true
result = result.to_liquid_value if result.respond_to?(:to_liquid_value)
if result
return block.attachment.render_to_output_buffer(context, output)
end
idx += 1
end
output