From 25d0520c677aca16ea4ad5c12eacded6da02789f Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Mon, 16 Jan 2023 13:44:16 +0100 Subject: [PATCH] Improve Shapes Friendliness of Batch::Loader For optimal performance in Ruby 3.2, it is preferable to define instance variables in a consistent order. Based on production data, it seems that Batch::Loader is one of the main offenders in our app: ``` Shape Edges Report ----------------------------------- 169 @cache 130 @queue 127 @executor 125 @sql_counter 119 @loader_key ``` --- lib/graphql/batch/loader.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/graphql/batch/loader.rb b/lib/graphql/batch/loader.rb index 646edf2..11da284 100644 --- a/lib/graphql/batch/loader.rb +++ b/lib/graphql/batch/loader.rb @@ -44,6 +44,13 @@ def current_executor attr_accessor :loader_key, :executor + def initialize + @loader_key = nil + @executor = nil + @queue = nil + @cache = nil + end + def load(key) cache[cache_key(key)] ||= begin queue << key