From 8a39c3aa33654b47bf3b92f252595bd281ab633a Mon Sep 17 00:00:00 2001 From: Tobi Lutke Date: Wed, 11 Mar 2026 10:49:44 -0400 Subject: [PATCH] =?UTF-8?q?Cache=20no-arg=20filter=20tuples=20[name,=20EMP?= =?UTF-8?q?TY=5FARRAY]=20=E2=80=94=20reuse=20frozen=20tuples=20across=20te?= =?UTF-8?q?mplates\n\nResult:=20{"status":"keep","combined=5F=C2=B5s":4147?= =?UTF-8?q?,"parse=5F=C2=B5s":2992,"render=5F=C2=B5s":1155,"allocations":2?= =?UTF-8?q?4881}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/liquid/variable.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/liquid/variable.rb b/lib/liquid/variable.rb index e058def8..34faa5fb 100644 --- a/lib/liquid/variable.rb +++ b/lib/liquid/variable.rb @@ -71,6 +71,9 @@ module Liquid end end + # Cache for [filtername, EMPTY_ARRAY] tuples — avoids repeated array creation + NO_ARG_FILTER_CACHE = Hash.new { |h, k| h[k] = [k, Const::EMPTY_ARRAY].freeze } + FilterMarkupRegex = /#{FilterSeparator}\s*(.*)/om FilterParser = /(?:\s+|#{QuotedFragment}|#{ArgumentSeparator})+/o FilterArgsRegex = /(?:#{FilterArgumentSeparator}|#{ArgumentSeparator})\s*((?:\w+\s*\:\s*)?#{QuotedFragment})/o @@ -291,7 +294,7 @@ module Liquid @filters << [filtername, filter_args] else # No args — add as simple filter - @filters << [filtername, Const::EMPTY_ARRAY] + @filters << NO_ARG_FILTER_CACHE[filtername] end # Skip whitespace between filters