Improvement: don't queue redundant recalcs#5406
Improvement: don't queue redundant recalcs#5406georgemac-labs wants to merge 1 commit intoportfolio-performance:masterfrom
Conversation
When new price data has been downloaded, check if a recalculation of the view is already pending, and if so, don't queue another one.
|
@georgemac-labs great idea. I was thinking of a way to reduce it, but this seems like a neat idea. Is there a particular reason why you run the markDirty now with Did you notice a difference with your data? Because with my file and on MacBook M1, the 300ms are more than enough to recalculate. Therefore I am thinking to increase this to 500ms. I also implemented 874eaf5 (still behind an experimental feature flag) that delays the update of a view if the user is currently editing a cell. |
It's what Claude did ;) But I think I understand the reason. If you don't call it async, this logic... ... runs Having dug into this, I will say that the variable name seems suboptimal, and also my description above is slightly off. The state that is stored is actually But the distinction is immaterial to the logic, because
Yes, as mentioned above: app is more responsive while updating quotes.
I can only say for me personally: I view price updates as an async process from a UX perspective. I know I'm going to have to wait a short while. I'm not concerned about making them a little faster, or having the views update instantaneously. My only concern is that the app remain responsive during updating, so I can click around a bit. |
|
@buchen having understood the code better, I'm a little dissatisfied with the resulting logic.
|
I am not sure if I understand your statement. Isn't the code using a timer?
Right now the time is triggering every 300ms. And the two things happen:
I understand your statement of separating the two. And you suggest: not check every 300 ms, but check 300 ms after the last recalculation was finished (of course we can also change the 300 ms to something else). I think that could remove the update pressure. We would still need the "timer" for the progress bar. Happy to entertain a pull request on this. |
Hi maintainers, I have been experiencing the UI responsiveness problem described here – i.e. PP becomes laggy when downloading quotes.
After a little analysis, I have a couple of ideas for improvements.
The lowest hanging fruit I see: when new price data is downloaded, that causes a view recalculation to be queued, even if there’s already a recalculation in the queue. And that can happen repeatedly. So… Aren’t we building a queue of redundant work here?
UI_PROGRESS_UPDATE_INTERVALdoes limit the damage by reducing the number of items added to the queue, but nonetheless it seems the current logic can burn CPU and slow down the app to do work that’s already been done once or more?So this PR simply stores whether there’s already an update pending. If true, don’t add to the queue, effectively limiting the queue to only one item (from price updates).
In my tests, this change seems to make the app more responsive while updating quotes.
Please note: I’m NOT confident I understand all the moving parts here, so apologies if I’ve overlooked something and this change doesn't make sense.