Saturday, February 26, 2022

Re: Slow page load performance with a large number of formsets (over 25)

However, caching the queryset solves only part of the problem.

If you have a formset with 100 forms, and each of these forms has a choice field with 100 choices (say 50 bytes each), then you have altogether 10k choices or 500k bytes of data. While, depending on the particular case, this may be manageable, it can get quickly out of hand if the forms become 200 or the choices become 200 or more etc.

A technical solution to that problem could be to retrieve the choices only once and have some JavaScript fill in the choices in the forms. But this departs from the Django formset paradigm and might require significant development.

The alternative I see would be to redesign the UI so that it doesn't need a formset (at least such a big formset). While I don't know the specifics of this particular case, I would hack my brains to see whether I can present this information in a more simple manner to the user (because 100 forms would be overwhelming I guess). Once I have a saner UI, the implementation details would follow naturally.

Antonis Christofides  +30-6979924665 (mobile)


On 26/02/2022 05.43, Jacob Greene wrote:
You would need to cache the queryset and pass it to each form instance that the formset creates. I've done this a few different ways in the past. I've never understood why there isn't a more straight forward way to do this. Here's a post with a few legit options depending on your use case:

On Fri, Feb 25, 2022, 8:53 PM Steve Smith <stevesmith0722@hotmail.com> wrote:

If in fact I am….how do I avoid this?  I have been playing with alternatives for a week and I'm starting to lose it…lol

 

Sent from Mail for Windows

 

From: Jacob Greene
Sent: Friday, February 25, 2022 5:58 PM
To: django-users@googlegroups.com
Subject: Re: Slow page load performance with a large number of formsets (over 25)

 

If you're using model choice fields, it's very likely you are making an SQL query for each form set. It should be pretty obvious in the log with debug turned on. 

 

On Fri, Feb 25, 2022, 4:31 PM Ryan Nowakowski <tubaman@fattuba.com> wrote:

Steven, are you using ModelFormSet?  If so, Is it the initial query
that's slow?  The form rendering?  Or is it the POST back to the server
that's slow?  You can use django-debug-toolbar[1] to profile your page
and get these metrics.

Once you figure out what part is slowest, then you can optimize.

Hope this helps!

Ryan N

[1] https://django-debug-toolbar.readthedocs.io/en/latest/

On Mon, Feb 07, 2022 at 09:12:48AM -0800, Steven Smith wrote:
> Did this issue ever get resolved?  I'm experiencing the same thing.  Once
> it hits 100 forms or so it gets pretty slow.
>
> On Monday, September 22, 2014 at 10:48:52 AM UTC-5 Collin Anderson wrote:
>
> > Yes, if you want speed, using javascript and ajax is probably your best
> > bet. It will probably also reduce merge-conflicts.
> >

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20220225222926.GH11627%40fattuba.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAF-Y%3De5Fp7kDtLq47Z3Y4GEjXMne2PcTLYxOJ8St5gkKCkpUpw%40mail.gmail.com.

 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CH0PR18MB42923C9432F56E071FA9716CD23F9%40CH0PR18MB4292.namprd18.prod.outlook.com.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAF-Y%3De4E3zFuzmK_UOf9exaEc5pM5FNun7xJXhn_yVbHyWqiWg%40mail.gmail.com.

No comments:

Post a Comment