graphql-python/graphene-django

Performance issues with large data sets and pagination.

Open

#829 ouverte le 19 déc. 2019

Voir sur GitHub
 (3 commentaires) (6 réactions) (0 assignés)Python (754 forks)batch import
help wanted✨enhancement

Métriques du dépôt

Stars
 (4 173 stars)
Métriques de merge PR
 (Merge moyen 12j 13h) (1 PR mergée en 30 j)

Description

It is known that GraphQL is not the fastest API when you have many objects, see: https://github.com/graphql-python/graphene/issues/268

If you have many objects, you want to use pagination with DjangoConnectionField.

I have run some benchmarks for this:

  1. There are 1000 items and i fetch 100 of them:
django v1.11.26
graphene v2.1.8
graphene-django v2.7.1
Use timeit statement: graphene.Schema(query=Query).execute('{Items(first: 100) {edges {node {id}}}}')
Run one timeit call... takes: 13.3 ms
timeit... use 5 * 75 loop...
max...: 10.84 ms
median: 10.66 ms
min...: 10.61 ms
cProfile stats for one request: 30148 function calls (28688 primitive calls) in 0.019 seconds
  1. There are only 100 items and i didn't use a DjangoConnectionField:
django v1.11.26
graphene v2.1.8
graphene-django v2.7.1
Use timeit statement: graphene.Schema(query=Query).execute('{Items {id}}')
Run one timeit call... takes: 13.3 ms
timeit... use 5 * 106 loop...
max...: 7.54 ms
median: 7.48 ms
min...: 7.29 ms
cProfile stats for one request: 18556 function calls (17830 primitive calls) in 0.012 seconds

Graphene already makes a lot of calls anyway. But with these two variants there is also a very clear difference to be noticed.

Guide contributeur