Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handling of potentially long running operations #721

Open
klassenjs opened this issue Mar 22, 2022 · 2 comments
Open

Better handling of potentially long running operations #721

klassenjs opened this issue Mar 22, 2022 · 2 comments
Milestone

Comments

@klassenjs
Copy link
Member

klassenjs commented Mar 22, 2022

For potentially long running operations (for example #720), evaluate moving the calculation to a worker (moving it out of the main UI thread) and providing user feedback if it isn't finished after a few seconds. Possibly via a progress bar and/or option to cancel.

@klassenjs
Copy link
Member Author

Looking at this more, I'm starting to really like the idea. It could potentially move all the JSTS/turf stuff out of the main geomoose.js library and into it's own worker. The worker would respond to messages for the various JSTS operations we support. Message could contain the operation type ('buffer', 'union', etc.) and the source GeoJSON. The worker returns the result GeoJSON. This likely involves copying the potentially large GeoJSON back and forth between the worker and main thread. There are some workarounds for this using Transferable objects (ArrayBuffer), but I don't know that using them is feasible/appropriate.

We'd need additional target libraries in the webpack config to generate the worker.js files. This isn't too hard (I've done this before). And it should significantly reduce the size of geomoose.js by not requiring JSTS linked in. This saves about 15% (300kB off geomoose.min.js, and 2MB off geomoose.js).

The real issue will likely be refactoring the JSTS calls to deal with the asynchronous nature of sending a message to a worker and waiting for a response. Unfortunately, the JSTS calls are part of the exported GeoMoose API (in index.js) so removing them or replacing them with async versions might not be allowed unless we go to a 4.0.0 release. Although we could always add async versions next to them and deprecate the existing versions, but then there is no savings in geomoose.min.js).

@klassenjs
Copy link
Member Author

I think the only place jsts is used in the code right now is in src/gm3/components/map/index.js:addSelectionFeatures(). I would have thought it would have been used in more places.

@theduckylittle theduckylittle added this to the 4.0.0 milestone Sep 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants