hoist write score check out of render loop: skip increment_write_score when no limits active

This commit is contained in:
Tobi Lutke
2026-03-11 08:04:40 -04:00
parent b86143eb0e
commit db434923d0
2 changed files with 7 additions and 3 deletions
+6 -2
View File
@@ -297,7 +297,11 @@ module Liquid
def render_to_output_buffer(context, output)
freeze unless frozen?
context.resource_limits.increment_render_score(@nodelist.length)
resource_limits = context.resource_limits
resource_limits.increment_render_score(@nodelist.length)
# Check if we need per-node write score tracking
check_write = resource_limits.render_length_limit || resource_limits.last_capture_length
idx = 0
while (node = @nodelist[idx])
@@ -312,7 +316,7 @@ module Liquid
end
idx += 1
context.resource_limits.increment_write_score(output)
resource_limits.increment_write_score(output) if check_write
end
output
+1 -1
View File
@@ -3,7 +3,7 @@
module Liquid
class ResourceLimits
attr_accessor :render_length_limit, :render_score_limit, :assign_score_limit
attr_reader :render_score, :assign_score
attr_reader :render_score, :assign_score, :last_capture_length
def initialize(limits)
@render_length_limit = limits[:render_length_limit]