hawolt / poe-regex

advanced map regex generator for path of exile
Other
7 stars 3 forks source link

Utilize web workers for background calculation #51

Open pfeigl opened 2 months ago

pfeigl commented 2 months ago

Is your feature request related to a problem? Please describe. When selecting multiple mods, calculations can (and will) slow down the browser

Describe the idea/solution you'd like Leveraging web workers (https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) the calculation can be made in the background.

I didn't check your code, but possibly the calculations can even be split into multiple sub-calculations which can be put into multiple web workers.

This might not only fix the lag but even improve calculation speed through a multi threaded architecture

hawolt commented 2 months ago

for now I have added a checkbox to prevent this issue, basically disabling auto-updates until you tell it to generate your regex

I am aware this is a bandaid fix for now until I figure out how to utilize web-workers for this, not really a frontend guy so I need my sweet time - leaving this issue open regardless until I have this added

pfeigl commented 2 months ago

Fair enough. I looked into it yesterday and with the current setup it's actually a little complicated to integrate. The calculation is not seperated enough right now, because it directly accesses the DOM and global variables which are managed outside of the calculation.

Specifically the buildModifierExpression and all sub methods would need to get all variables provided as parameters and not access global variables. With this change, it would be kinda easy to move the calculation into a web worker. I might find time on the weekend to look into it if you want.

hawolt commented 2 months ago

thanks for taking your time to take a look, so in theory it should suffice if the global variables are passed to the function? should be a quick change, not sure if the asynchronous operation from the webworker would be interfered with if something changes whilst its still working on it.. I guess passing a 'clone' of whatever variable or array should solve this though.

if I have some time tomorrow I will prepare the functions and then just the webworker stuff would need to get added

hawolt commented 2 months ago

just as an update I wont have time for the change this weekend sadly