dnsev / 4cs

Media player userscript, steganographic embedding
https://dnsev.github.io/4cs
15 stars 3 forks source link

Firefox/Greasemonkey Speed Issues #45

Closed dnsev closed 10 years ago

dnsev commented 10 years ago

This has been an annoyance for Firefox users/myself when using 4cs to play sounds files. Greasemonkey's Javascript seems to run significantly slower than Chrome, and even embedded Javascript code.

This issue is going to be used to:

This way, I can see if there's anything that can be done to make this less of a problem.

The userscript can be found here. It runs exclusively on this page.


dnsev commented 10 years ago

Firefox native:

basic_loop
  Iterations: 2,000,000
  Repetitions: 20
  Minimum time: 2.2012600399173152ms
  Maximum time: 4.435046565579569ms
  Average time: 3.5112040190689298ms
  Average iterations/second: 569,605,181

file_read_loop
  Iterations: 1
  Repetitions: 20
  Minimum time: 1.3600889780086618ms
  Maximum time: 1.8275066250125747ms
  Average time: 1.4096466930954308ms
  Average iterations/second: 709

Firefox Greasemonkey extension:

basic_loop
  Iterations: 2,000,000
  Repetitions: 20
  Minimum time: 11.90951252134164ms
  Maximum time: 15.972010356673763ms
  Average time: 12.258645193564007ms
  Average iterations/second: 163,150,166

file_read_loop
  Iterations: 1
  Repetitions: 20
  Minimum time: 10.063032112977453ms
  Maximum time: 10.52201696738075ms
  Average time: 10.227185456083088ms
  Average iterations/second: 98

Nightly native:

basic_loop
  Iterations: 2,000,000
  Repetitions: 20
  Minimum time: 1.6708930905497255ms
  Maximum time: 5.094597606298066ms
  Average time: 2.5410946939807557ms
  Average iterations/second: 787,062,365

file_read_loop
  Iterations: 1
  Repetitions: 20
  Minimum time: 1.1230642275884293ms
  Maximum time: 1.6651708539384344ms
  Average time: 1.1568555406309202ms
  Average iterations/second: 864

Nightly Greasemonkey extension:

basic_loop
  Iterations: 2,000,000
  Repetitions: 20
  Minimum time: 158.38608833928447ms
  Maximum time: 160.7511790819117ms
  Average time: 159.28210024153867ms
  Average iterations/second: 12,556,339

file_read_loop
  Iterations: 1
  Repetitions: 20
  Minimum time: 120.09288093531359ms
  Maximum time: 121.99236231997565ms
  Average time: 121.1077497153943ms
  Average iterations/second: 8

Chrome native:

basic_loop
  Iterations: 2,000,000
  Repetitions: 20
  Minimum time: 1.9999999985884642ms
  Maximum time: 5.9999999994033715ms
  Average time: 3.349999999954889ms
  Average iterations/second: 597,014,925

file_read_loop
  Iterations: 1
  Repetitions: 20
  Minimum time: 18.000000000029104ms
  Maximum time: 19.00000000023283ms
  Average time: 18.400000000110595ms
  Average iterations/second: 54

Chrome Tampermonkey extension:

basic_loop
  Iterations: 2,000,000
  Repetitions: 20
  Minimum time: 1.9999999985884642ms
  Maximum time: 5.9999999994033715ms
  Average time: 2.8999999999541615ms
  Average iterations/second: 689,655,172

file_read_loop
  Iterations: 1
  Repetitions: 20
  Minimum time: 16.999999999825377ms
  Maximum time: 18.000000000029104ms
  Average time: 17.79999999998836ms
  Average iterations/second: 56
dnsev commented 10 years ago

On a (much) lower spec'd computer:

Firefox 18.0.1/Nightly 21.0a1 native:

basic_loop
  Iterations: 2,000,000
  Repetitions: 20
  Minimum time: 2.853437855510947ms
  Maximum time: 3.867154374911024ms
  Average time: 3.0095648644754873ms
  Average iterations/second: 664,547,896

file_read_loop
  Iterations: 1
  Repetitions: 20
  Minimum time: 1.4521993248981744ms
  Maximum time: 2.4831471920056174ms
  Average time: 1.5426089067003885ms
  Average iterations/second: 648

Firefox 18.0.1/Nightly 21.0a1 Greasemonkey extension:

basic_loop
  Iterations: 2,000,000
  Repetitions: 20
  Minimum time: 2.8523379822545394ms
  Maximum time: 6.3561675576256675ms
  Average time: 3.442658291009593ms
  Average iterations/second: 580,946,417

file_read_loop
  Iterations: 1
  Repetitions: 20
  Minimum time: 1.4445002120937716ms
  Maximum time: 2.79771094377611ms
  Average time: 1.5712789362905824ms
  Average iterations/second: 636

Firefox 26 native:

basic_loop
  Iterations: 2,000,000
  Repetitions: 20
  Minimum time: 2.133387495980969ms
  Maximum time: 3.3377487134232524ms
  Average time: 2.249405793472408ms
  Average iterations/second: 889,123,699

file_read_loop
  Iterations: 1
  Repetitions: 20
  Minimum time: 1.4364344748671556ms
  Maximum time: 2.1733495576861515ms
  Average time: 1.4932612598607875ms
  Average iterations/second: 670

Firefox 26 Greasemonkey extension:

basic_loop
  Iterations: 2,000,000
  Repetitions: 20
  Minimum time: 17.18478640644662ms
  Maximum time: 24.878033221306396ms
  Average time: 17.749516330734696ms
  Average iterations/second: 112,679,127

file_read_loop
  Iterations: 1
  Repetitions: 20
  Minimum time: 15.018402712727948ms
  Maximum time: 15.83560854337702ms
  Average time: 15.255205425161922ms
  Average iterations/second: 66

Chrome (31.0.1650.63 m) native:

basic_loop
  Iterations: 2,000,000
  Repetitions: 20
  Minimum time: 2.9999999999290594ms
  Maximum time: 10.000000000104592ms
  Average time: 3.9500000000032287ms
  Average iterations/second: 506,329,114

file_read_loop
  Iterations: 1
  Repetitions: 20
  Minimum time: 28.999999999996362ms
  Maximum time: 33.00000000001546ms
  Average time: 30.55000000001087ms
  Average iterations/second: 33

Chrome (31.0.1650.63 m) Tampermonkey extension:

basic_loop
  Iterations: 2,000,000
  Repetitions: 20
  Minimum time: 1.9999999999527063ms
  Maximum time: 4.000000000132786ms
  Average time: 3.150000000005093ms
  Average iterations/second: 634,920,635

file_read_loop
  Iterations: 1
  Repetitions: 20
  Minimum time: 37.00000000003456ms
  Maximum time: 41.99999999991633ms
  Average time: 38.09999999999718ms
  Average iterations/second: 26
dnsev commented 10 years ago

This is somewhat resolved in 5.0/cl

It works by injecting the image decoding code into the webpage as a <script> element, and also running it in that scope.

This "compiles" it (or whatever it's doing) differently than Greasemonkey does, and seems to run at/closer to native speeds.

Close to a 10x speed increase in the files I tested.

Hopefully this doesn't happen again because this was a pain.