graphql-client
graphql-client copied to clipboard
Optimize Schema.set_class
constants.include? allocate an array every time and does an O(N) search.
const_defined? saves that allocation and does an O(1) lookup.
Additionally it's more correct since it will return true for private
constants while Module#constants won't include private constants.
For context one of our app spend 10-15% of boot time in there:
==================================
Mode: wall(1000)
Samples: 17329 (4.89% miss rate)
GC: 3219 (18.58%)
==================================
TOTAL (pct) SAMPLES (pct) FRAME
2657 (15.3%) 2657 (15.3%) (marking)
2524 (14.6%) 2524 (14.6%) Module#constants
==================================
Mode: cpu(1000)
Samples: 20400 (4.93% miss rate)
GC: 4513 (22.12%)
==================================
TOTAL (pct) SAMPLES (pct) FRAME
3856 (18.9%) 3856 (18.9%) (marking)
2569 (12.6%) 2569 (12.6%) Module#constants