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

Really slow for huge list of objects #319

Closed
levrik opened this issue Feb 13, 2020 · 13 comments
Closed

Really slow for huge list of objects #319

levrik opened this issue Feb 13, 2020 · 13 comments
Labels
enhancement New feature or request roadmap Feature that we want to have included
Milestone

Comments

@levrik
Copy link

levrik commented Feb 13, 2020

type FooBar {
  # some more flat fields
}

type Bar {
  n: Int!
  sub: FooBar!
}

type Foo {
  foo: [Bar!]!
}

We have a structure like this. The foo property on Foo can contain thousands of items. Sadly we need all of them at once, so we can't paginate over it.
There's only one resolver to resolve foo itself which is quite fast (getting the nested object from a Mongo DB).
Our current workaround is to implement a custom JSON scalar which just returns the data, by-passing all child resolvers. But this way we're loosing everything that GraphQL gives us.
Is there anything that can be used to speed this up without using a JSON scalar or is this the best solution already? I know that GraphQL comes with some overhead but this can go up to 20 seconds vs 1 second with JSON scalar.

We're using Ariadne in sync-mode.

@rafalp
Copy link
Contributor

rafalp commented Feb 13, 2020

Performance discussion for GraphQL Core Next: graphql-python/graphql-core#54

I'm afraid there isn't much we can do in Ariadne to speed things up for cases such as these. Query executor does plenty of function calls to resolve values. There's functions all the way down, with at least 3 for each value returned for field: resolver call, isawaitable check, scalar serialize call for the returned value. This easily adds up if you have A LOT of data.

Low hanging fruit for Ariadne that comes to mind would be adding cache to query parser (parsing complex queries can make up to 20% of query execution time), but that's really only buying time before somebody else returns even more data from their query.

@levrik
Copy link
Author

levrik commented Feb 13, 2020

I just did some profiling and, indeed, the slowest part is everything that is happening inside graphql-core-next. Then probably the JSON scalar is the best fit here.

@Dodobibi
Copy link

Dodobibi commented Mar 9, 2020

I think than graphql-core-next must be written in C (cython) for drastically increase performances. My first tests confirm this.

I'm trying to rewrite it with cython but it's a huge work.
This is the only way to increase performances, when recursives calls...

@patrys
Copy link
Contributor

patrys commented Mar 9, 2020

Out of curiosity, have you considered using PyPy? (Disclaimer: it only supports Python 3.6 for now, 3.7 support is underway.)

@Dodobibi
Copy link

Dodobibi commented Mar 9, 2020

Out of curiosity, have you considered using PyPy? (Disclaimer: it only supports Python 3.6 for now, 3.7 support is underway.)

I can't (I need last version of hypercorn wich need python >= 3.7)

Have you tried with pypy ? What about the performances ?

@patrys
Copy link
Contributor

patrys commented Mar 9, 2020

I don't have any precise data about Ariadne to share but I've heard people mention that in their tests PyPy made pure-Python ASGI servers as fast as uvicorn or hypercorn.

@rafalp
Copy link
Contributor

rafalp commented Mar 30, 2020

Looks like graphql-core 3.1 is promising performance improvements in query executor, but we'll have to update our codebase to support it.

@levrik
Copy link
Author

levrik commented Sep 1, 2020

@rafalp Looks like this could improve with the 0.13 of Ariadne?

@rafalp
Copy link
Contributor

rafalp commented Sep 1, 2020

@levrik correct. We've updated GraphQL-Core to 3.1 in 0.13 and will ship it in few weeks, once the rest of features pull requests have been merged.

@rafalp rafalp added this to the Ariadne 0.13 milestone Sep 1, 2020
@rafalp rafalp added enhancement New feature or request roadmap Feature that we want to have included labels Sep 1, 2020
@rafalp
Copy link
Contributor

rafalp commented Sep 1, 2020

For the record, here's the PR: #393

@cancan101
Copy link
Contributor

@rafalp any updates on getting the 0.13 release of Ariadne published with the upgrading of graphql-core to 3.1 change?

@rafalp
Copy link
Contributor

rafalp commented Mar 4, 2021

I want to release 0.13 soon with GraphQL core bumped to 3.1.3.

@rafalp
Copy link
Contributor

rafalp commented Mar 17, 2021

Ariadne 0.13 has been released. Closing this.

@rafalp rafalp closed this as completed Mar 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request roadmap Feature that we want to have included
Projects
None yet
Development

No branches or pull requests

5 participants