Skip to content

Commit

Permalink
Improve Shapes Friendliness of Batch::Loader
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
byroot committed Jan 16, 2023
1 parent 8873ffd commit 25d0520
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/graphql/batch/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 25d0520

Please sign in to comment.