rmosolgo / graphql-ruby

Ruby implementation of GraphQL
http://graphql-ruby.org
MIT License
5.38k stars 1.39k forks source link

Add top-level caches for Schema::Visibility #5157

Closed rmosolgo closed 2 weeks ago

rmosolgo commented 2 weeks ago

Fixes #5154

This adds a top-level cache, like Schema makes when using Warden, but it supports lazy-loading. Currently, the cache rebuilds whenever something is lazy-loaded, but it could probably be made to grow in-place instead if it becomes a problem.

Running the same benchmark from the original issue shows good results:

$ N=1000 ruby types_bench.rb
GraphQL gem 2.4.2--accessing `GraphQL::Schema#types` 1000 times
                           user     system      total        real
Not using Visibility   0.291171   0.012367   0.303538 (  0.303684)
Using Visibility       0.156794   0.005118   0.161912 (  0.162134)