strawberry-django icon indicating copy to clipboard operation
strawberry-django copied to clipboard

Slow startup when defining many filters

Open arthanson opened this issue 2 months ago • 5 comments

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

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

arthanson avatar Apr 18 '24 16:04 arthanson

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? 😊

patrick91 avatar Apr 18 '24 17:04 patrick91

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.

arthanson avatar Apr 18 '24 17:04 arthanson

@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

bellini666 avatar Apr 20 '24 15:04 bellini666

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?

Kitefiko avatar Apr 30 '24 16:04 Kitefiko

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)

bellini666 avatar May 01 '24 13:05 bellini666