Skip to content
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

Optimized batch loading without blocking #628

Open
hypirion opened this issue Dec 26, 2023 · 2 comments
Open

Optimized batch loading without blocking #628

hypirion opened this issue Dec 26, 2023 · 2 comments

Comments

@hypirion
Copy link

This is more or less the same issue as gqlgen's 99designs/gqlgen#518

Right now, there doesn't seem to be any way to defer evaluation and loading of elements -- you're forced to load elements inside the resolver instead of passing something that can be loaded in batch by the GraphQL resolver itself (e.g. a dataloader thunk). That means the dataloader has to wait a predefined amount of time (by default 16 milliseconds if you use https://github.com/graph-gophers/dataloader) and you need one goroutine per resolver that waits on the loader.

If the method resolvers were allowed to return a thunk as well (func () (T, error)) or something more exotic, the server implementation could walk the query and gather all thunks. Then, when there is nothing more to expand but thunks, the server could evaluate the highest ones up in the tree and repeat the evaluation step once more. In that way, you reduce the number of goroutines needed and can immediately trigger the resolvers instead of having to wait for a timeout. This is what graphql-java does, except it also tracks what kind of loaders are in use, so that it only spawns a single "goroutine" per batch loader.

Is this something that'd be interesting to implement for graphql-go? If yes, we can probably think out the specifics for how it's supposed to be implemented. I'm imagining something that could work like Jens Neuer's Dataloader v3.0, except being backwards compatible with the current evaluation order when thunks aren't used.

@pavelnikolov
Copy link
Member

@hypirion This is an interesting approach and I haven't thought about it. It's similar to the way the dataloader package handles loading.

Do you think that this can be implemented in a backwards compatible way? I'm curious about the performance improvements of such an implementations too.

@vikstrous2
Copy link

I ran into this article, which seems to talk about the same thing. I'm very interested in removing the need for loaders.

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

No branches or pull requests

3 participants