WasatchPhotonics / ENLIGHTEN

Open-source spectroscopy application for controlling and taking measurements from Wasatch Photonics spectrometers.
https://wasatchphotonics.com/product-category/software/
MIT License
3 stars 6 forks source link

Architecture Backlog. #320

Open samiebee43 opened 10 months ago

samiebee43 commented 10 months ago

Right now, most "background" activities are actually ticked by QTimers, which fire in the GUI thread. This means that the GUI actually freezes during these scheduled tasks. It wasn't really noticable when the tasks were all quite short, but when we added the External API, which can shuttle quite large volumes of data around in queued requests and responses, it became apparent that the GUI grows jerky during these activities (specifically, new spectra is not graphed).

The solution is to reduce utilization of QTimers for anything that might involve significant processing, serialization, subprocess communications etc. The most likely replacement is probably a QThread, noting that these can't directly access (change? read?) GUI widgets, so any GUI updates resulting from background QThreads would need to be dispatched to the GUI thread, probably using Signals (the mechanism Qt provides for this purpose), or perhaps thread-safe queues and the like.

samiebee43 commented 10 months ago

Copying from README_BACKLOG.md, but personally I prefer writing blocking handlers with callback durations < 17ms. Larger tasks can often be broken into smaller sub 17ms sections that get dispatched by the mainloop. This technique makes for very predictable code.