Callback execution is sometimes delayed. How to debug?

I use the same callback in my application in multiple places. To be precise, I register the same Python function multiple times using callback with different Inputs and Outputs. In some places, the callback is very responsive. In other places, there is a significant delay between an Input property change on the client (i.e. I type in an input field) and the execution of the callback on the server (i.e. the execution of a print call at the beginning of my Python function). I would like to avoid this delay. Through extensive testing, I can rule out all the following possible causes:

  1. Pattern matching: The callbacks do not use pattern matching.
  2. Debounce: The inputs do not use debounce properties, and the delay is not consistent.
  3. Data transfer: The Inputs and Outputs are not very large (at most 50 single-word strings). More importantly, the callback is significantly delayed on one page in a low-data use case, but perfectly responsive on another page in a large-data use case.
  4. DOM updates: The delay is between an input change on the client and the execution of the callback function on the server, not between the execution of the function and the changes on the client.
  5. Slow Python code: Using the time module, I can confirm that the execution time of the Python function is negligible.
  6. Network latency: All of this is happening in my local development environment.

I have the suspicion that Dash introduces the delay by not reacting properly to changes in my Inputs. I do not share my code here, because I can not reproduce the delay with a minimal example, and I can not share the corporate application. I am not asking for code suggestions. Instead, I would like to know how I could confirm or refute my suspicion using Python, Dash, or Firefox developer tools? Or alternatively, if there are any possible causes of delay that I might have overlooked?

Hello @Niklas_Kappel,

Welcome to the community!

More than likely you are encountering an issue with the synchronous server, in that all requests go into a conga line and have to be served in the order that they were received. Running on local normally helps with this, but you will still see it from time to time.

Workarounds would be to offload as much as possible to the clientside_callbacks, keeps the latency low and also allows the server to only handle requests that the server is needed for.

Hey, thanks for the quick reply. Is there a way to watch the queue? From what I see in the Firefox dev tools “Network” tab, I experience the delay on a specific page even though there are no requests to the server except for the ones I cause by interacting with my Inputs.

You can watch what the Python server is responding to by not running in debug mode.

Then whatever delay in the _dash-update-component or similar endpoint will show the delay on the server as well.