-
-
Notifications
You must be signed in to change notification settings - Fork 565
Lazy loading of types... #425
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
Comments
You are right here. Types are being initiated on But instance creation is not expensive. It's fields, arguments, and interfaces which add significant overhead. If you don't create them on type instantiation you should get a significant performance win (which we benchmarked). We actually considered loading types by name, but it didn't pass a cost/benefit analysis at the moment (wins were little, costs to implement were relatively significant). Anyways, if you do some benchmarks, illustrating the opposite we can get back to this idea. But we really need some numbers to back it up. |
Well, I make heavy use of inline schema definitions. All of my mutations, for example, are dynamically generated with custom types (with custom validation types, error codes, and so on), and many of my queries are also dynamically created. It's just a lot of busy work that I would rather not have happen if it doesn't need to. But as you say, I should do some profiling before pressing the matter. I'll see what I can come up with tomorrow. |
In order for the typeLoader to be called with the type name, isn't the type object already loaded? I'm just trying to wrap my head around why the typeLoader needs to return a type that it should already have. |
Before type loading, we had to scan the whole schema top-to-bottom to discover all possible types. This was required mostly because of the abstract types (interfaces, unions). E.g. Another scenario when type loading is useful is when the schema is defined via SDL. Then we have a type name from the SDL before we actually create type instance. Technically if there were no SDL and abstract types, we could have avoided type loading at all, but then we had to couple either schema and execution (executor should've somehow registered all types loaded during execution in the schema) or couple schema and each type definition (definition should've notified schema when it has been loaded). Both approaches were adding unnecessary complexity and added restrictions to independent schema usage. So at the moment, all that type-loading does is helping us to avoid full schema scanning. Plus, it opens ways for other optimizations (one day we may get back to the idea of defining type names as strings #62 for a fully lazy-loaded solution) |
There is one more issue with the custom typeLoader. For example - we have a lot of inline type instantiations within our fields. The validation fails because of that cause for inline types you cannot get a single instance from For eg.
The problem |
I'm currently experience either some understanding issue about lazy loading or some implementation issue. Currently, all types of all my queries and mutations on the schema are resolved, which keeps me awake since days. A Query Class looks like
If a run a query, which DOES NOT involve this class, it is still resolved with all it's dependent types. Thanks for clarification. |
@spawnia I was going to close this once all the little fix-up patches and optimizations were sorted out and released, but I suppose there's no harm in doing it now. Thanks much. |
I have a large number of types (130+) in my code base, and I'm worried about the overhead of building them all for every little request. I followed the advice in your documentation, and made sure that my objects return callbacks for their
field
properties, and I provided atypeLoader
callback when instantiating mySchema
. I understand the general concept, but I must be missing a piece, because at least some types are still being constructed even though they are not referenced in any way by the query being made.After analyzing the sample here it's not clear to me where the savings are. Imagine if
MyTypeA
had a list of 100 fields on it instead of 1; wouldn't 100 calls to$this->get(<fieldName>)
trigger as soon as itsfields
callback resolves? Or is there some magic I'm missing?I guess I was expecting something more like this:
...with the idea being that I use the name of the type in my field definition rather than a reference to the field itself, and then at runtime it would use the name to look up the type when needed.
I'm pretty sure this is just a matter of me being dumb and not getting something fundamental, so I guess my real question here is whether you think the lazy loading documentation could be improved a bit, or perhaps incorporated into the samples. If you can help me get my questions sorted out I'd be happy to help with either.
Thanks for the wonderful library!
The text was updated successfully, but these errors were encountered: