Fast-path Hash lookups in VariableLookup#evaluate — skip respond_to? checks for Hash objects\n\nResult: {"status":"keep","combined_µs":4110,"parse_µs":2922,"render_µs":1188,"allocations":25535}

This commit is contained in:
Tobi Lutke
2026-04-04 17:42:33 -07:00
committed by Chris Pak
parent 41de814045
commit 3f9b8916b2
+3 -2
View File
@@ -177,9 +177,10 @@ module Liquid
# If object is a hash- or array-like object we look for the
# presence of the key and if its available we return it
if object.respond_to?(:[]) &&
if object.instance_of?(Hash) ? object.key?(key) :
(object.respond_to?(:[]) &&
((object.respond_to?(:key?) && object.key?(key)) ||
(object.respond_to?(:fetch) && key.is_a?(Integer)))
(object.respond_to?(:fetch) && key.is_a?(Integer))))
# if its a proc we will replace the entry with the proc
object = context.lookup_and_evaluate(object, key)