-
Notifications
You must be signed in to change notification settings - Fork 528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reuse the resolution struct to avoid unnecessary allocations #636
Conversation
definition: nil, | ||
arguments: nil | ||
} | ||
|> Map.merge(common) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%{adapter: adapter, context: context, acc: acc, root_value: root_value, schema: schema, fragments: fragments, fields_cache: fields_cache} = exec
%Absinthe.Resolution{
path: nil,
source: nil,
parent_type: nil,
middleware: nil,
definition: nil,
arguments: nil,
adapter: adapter,
context: context,
acc: acc,
root_value: root_value,
schema: schema,
fragments: fragments,
fields_cache: fields_cache
}
explicit maps should be even slightly more performant, though quite verbose in here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this allocation happens just once per request though, the biggest win was https://github.com/absinthe-graphql/absinthe/pull/636/files#diff-9e88b6c0fafa4e1d518da81f1c8f16a8L195 which is called for every field, potentially thousands of times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so a resolution is still created on every request? I was noticing how big that struct is and wondered if it would slow things down to be created on every request when you are trying to handle dozens per second on an instance. googling led me here :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @atomkirk dozens of requests per second should be trivially achieved on a single instance, the presence of large maps is not going to be your bottleneck.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it probably also greatly reduces allocations when the vast majority of the keys are atoms. I would assume atoms are shared across all of the vm's processes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct, structs benefit from the VM's constant heap allocation. Not just the keys, but the entire "key structure" part of the map is allocated once when the application boots, and then referenced.
Wide Query
Deep Query