Skip to content

Cache field and type lookups in Visibility::Profile#5586

Merged
rmosolgo merged 1 commit intomasterfrom
cache-visibility-profile-lookups
Mar 25, 2026
Merged

Cache field and type lookups in Visibility::Profile#5586
rmosolgo merged 1 commit intomasterfrom
cache-visibility-profile-lookups

Conversation

@swalkinshaw
Copy link
Copy Markdown
Collaborator

Memoize the results of field(owner, field_name) and type(type_name) since validation traverses the same fields/types repeatedly, especially when expanding fragments. Safe because profiles are per-query objects.

This optimization really only shows up with visibility profiles enabled like you'd have in production. I forced a validation profile and pre-warmed it on the validation benchmarks and then the existing ones were 11-18% faster with this optimization. I've included that new validate_profile benchmark but not sure if there's a better way to do them.

Extracted from #5578

@rmosolgo
Copy link
Copy Markdown
Owner

Awesome, thanks for this. It looks like something went wrong, maybe with freezing the object. My first guess is that we need to pre-fill the cache in this method:

def preload
load_all_types
@all_types.each do |type_name, type_defn|
if type_defn.kind.fields?

Probably type(type_name) would work here -- I see that field(...) is already called below.

Memoize the results of field(owner, field_name) and type(type_name)
since validation traverses the same fields/types repeatedly, especially
when expanding fragments. Safe because profiles are per-query objects.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@swalkinshaw swalkinshaw force-pushed the cache-visibility-profile-lookups branch from e1ccd1e to 85f0404 Compare March 24, 2026 15:17
@swalkinshaw
Copy link
Copy Markdown
Collaborator Author

Tests are good with that type call 👍

@rmosolgo
Copy link
Copy Markdown
Owner

Thanks for this improvment!

@rmosolgo rmosolgo merged commit 6d1e5fa into master Mar 25, 2026
13 checks passed
@rmosolgo rmosolgo added this to the 2.5.23 milestone Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants