strawberry-graphql / strawberry-django

Strawberry GraphQL Django extension
https://strawberry.rocks/docs/django
MIT License
406 stars 117 forks source link

Slow startup when defining many filters #519

Open arthanson opened 5 months ago

arthanson commented 5 months ago

Startup time for the app increases linearly as more filters and annotated types are added.

Describe the Bug

We have converted NetBox from graphene to Strawberry - one things we noticed is a large jump in startup times, tracing this down it was from Strawberry processing all the filters and annotated types (we have a lot defined). When using graphene there was no noticeable delay in startup time.

timing to create the schmea without the filterset annotations: 219.61 ms timing with the annotations: 4568.14 ms

The startup delay is fairly linear as you add more and more filter fields. Unfortunately it is difficult to provide an example project as it is only noticeable when you have a large number defined.

Upvote & Fund

Fund with Polar

patrick91 commented 5 months ago

The startup delay is fairly linear as you add more and more filter fields. Unfortunately it is difficult to provide an example project as it is only noticeable when you have a large number defined.

how large? 😊

arthanson commented 5 months ago

In our case we have 105 Filters / Models and 2333 filter fields (average 22 / Filter), but it goes up fairly linearly, so with half the number of items it would be about 1/2 the delay, so I'm guessing you would need around 300 filter fields across several models to really start noticing it.

bellini666 commented 5 months ago

@arthanson that's interesting. I wonder if the most recent refactor of filters made it worse...

As I don't have something that large to test, could you help us by providing a sampling profile of your startup execution? You can use https://github.com/benfred/py-spy or something similar for that

Kitefiko commented 5 months ago

Hello, I would like to way in on this, that is, overall slow startups for larger projects.

This might be good place to try push for Object Type Extensions. I have created prototype, that I currently (with monkey patch unfortunately) use for my own project. The idea is to be able to customize fields directly during strawberry's _process_type and not being forced to loop over and override already created fields.

I do not know. If going a "monkey patch" way would be acceptable, but I could do demo for this lib, if your guys would see potential in this?

bellini666 commented 5 months ago

Hello, I would like to way in on this, that is, overall slow startups for larger projects.

This might be good place to try push for Object Type Extensions. I have created prototype, that I currently (with monkey patch unfortunately) use for my own project. The idea is to be able to customize fields directly during strawberry's _process_type and not being forced to loop over and override already created fields.

I do not know. If going a "monkey patch" way would be acceptable, but I could do demo for this lib, if your guys would see potential in this?

Just saw your prototype and I like the idea! :)

Left a couple comments in there, but it seems simple enough for me. I'll discuss it with @patrick91 soon (he is our currently for personal reasons)