Slow response from Dash app server with lots of States

#1

I’m using Dash to build a rather large form that has has a callback with around 1600 States. I know this is not exactly what Dash was designed for, but that I can use Dash to build these forms in Python is pretty compelling.

Everything is working fine except that the request to ‘_dash-update-component’ for my callback is taking around 9 seconds. I tried profiling the Flask app using the WerkZeug middleware profiler (eg app.server.wsgi_app = ProfilerMiddleware(app.server.wsgi_app)) and couldn’t see anything pathological going on. There was actually some improvements to the dispatch function in dash.py I could make to speed things up (creating a dictionary of state objects in order to link them to the relevant component_registration rather than scanning the list repeatedly) however this only took the time in dispatch down from around 0.6 seconds to around 0.1 seconds.

The whole request is only taking around 0.2 seconds according to the profiler. And furthermore, I’m not returning a large payload, just some text. Oh and it seems to be only an issue when the callback fires on the initial page load. Subsequent requests for this callback are a reasonable time.

So I’m wondering where the 9 seconds might be coming from?

#2

Hm, that’s odd. Could you create a simple example that reproduces this behaviour?

Just curious, what are you using 1600 states for?

#3

I’m using it to create a (large) form for an annotation task for my research (in computational linguistics). While this could be achieved using a more conventional Flask app, I thought it would be a good opportunity to see how I would do it in Dash. Once I got my head around safely using global variables to link the generated layout from a CSV file with the calllback that process the form (I’m assuming only one user art a time) it works pretty well.

I’ve made it available at http://nedned.net:8000/ (feel free to play around with it, this isn’t the instance being used). I’m afraid I don’t have time to convert it into a minimal working example of the problem, however I’ve packaged it up here, and there’s both a requirements.txt and a ‘run’ script you should be able to just run once you setup a virtualenv.

I’ve also tested it on localhost, and the issue persists, so it doesn’t appear to be a networking issue.

1 Like
#4

Thanks @nedned! That is a wicked cool app :slight_smile:
I’ll take a look at this and try to see what the hold up is.

#5

Thanks a bunch!

Also, interestingly, I’ve found that the client-side interface is quite sluggish in terms of responsiveness on the latest version of Chrome but is much snappier on Firefox. Apparently the newish ReactDOM 16 features a rewrite claiming better rendering performance, but I don’t know enough about React to know whether it would be relevant here.

#6

Hi @nedned,

I have a similar situation where I have callbacks with numerous inputs and states and my dash page has progressively gotten more and more sluggish. Do you have any tips ?

#7

Unfortunately I never got to the bottom of the slow performance in that app

#8

I see- thank you. I shall share my results if I am able to create steps to improve performance.