sharmaeklavya2 / packing-game

2D geometric bin-packing game in the browser
https://sharmaeklavya2.github.io/packing-game/
8 stars 4 forks source link

Don't block on long algorithms #21

Open sharmaeklavya2 opened 3 years ago

sharmaeklavya2 commented 3 years ago

Currently, long packing algorithms like opt-guill-ks block the main thread, which makes the UI unusable. We should have a way of running it in a non-blocking way and allow the user to cancel the algorithm.

Maybe we can wrap these algorithms in a web worker.

Another alternative is to convert these algorithms to generators, and add yield statements at appropriate points. This allows us to pause and resume them. The drawback is that it can be tricky to add yield statements appropriately. If yields are too far apart in time, then we will continue to face main-thread-blocking, and if they are too close together, then the packing algorithm's performance may get degraded.