jvail / glpk.js

GLPK for browser & node
GNU General Public License v3.0
106 stars 19 forks source link

Erratic performance on Firefox #21

Closed mikesol closed 3 years ago

mikesol commented 4 years ago

Hi,

I've noticed that sometimes, glpk.js takes up to 5x more time to process a linear program than normal on Firefox. I've created a small example to show this: https://glpk-js-loop-test.surge.sh/. If you open up the console, I've set it to print whenever processing takes more than 55ms. If you right-click "View page source" and scroll down to line 1235 (everything before that is the linear program), you'll see that the web worker acts as a FIFO queue. The queue's throughput should be regular, but every few seconds there is an outlier of an order of around 5x. I'm wondering if this is a Firefox issue or if there is a setting in emscripten that would help fix this?

Thanks! ~Mike

jvail commented 4 years ago

Hi,

the only spontaneous idea I have is that emscripten needs to increase memory sometimes and that will cost some time. I could not check the time reported by glpk (part of the return value) because it was not available in your example. If that is more or less the same for every run it is an emscripten issue and you could try compiling with this extra setting

-s INITIAL_MEMORY=16MB

or any other large value. Let me know if this helps then I will include this setting.

Jan

mikesol commented 4 years ago

I followed your recommendation and the outcome was interesting: on average, completion took ~20ms longer, but the result is more regular and only spikes once every ~20 seconds. I've put it here for reference: https://glpk-js-loop-test-2.surge.sh.

jvail commented 4 years ago

I am not sure what the effect of your setInterval() might be. You could try just sending a hundred or so lps into the worker without your queue.

mikesol commented 4 years ago

It's to mirror my use case more closely - I am using GLPK as part of a FRP algorithm, so there is an event triggered every n milliseconds.

mikesol commented 4 years ago

Here is a link with a bit more information: https://share.firefox.dev/2ZR7r2l. The peaks are where the slow-down occurs

jvail commented 4 years ago

Thank you, interesting. As far as I can see it is the garbage collector that is busy in theses orange peeks. Still, I think your setInterval might be part of the problem - if you want to figure out why there are peeks. First it is not guaranteed that it will fire exactly every 30ms and then there might be an overlap where you receive a result, you set the now.now = nt; which is not necessarily the start time if you have to wait for the next interval.