GoatSalad / megukascript

Userscript for the meguca imageboard
5 stars 3 forks source link

Improve performance of secret images #45

Closed dasdgdafg closed 6 years ago

dasdgdafg commented 6 years ago

response.response is really slow after loading the file, so instead use response.responseText. Also check the "secret" and length directly from the responseText, and only create the TextDecoder and ArrayBuffer if we're actually going to need them.

Performance before (loading 4 images which were 4.8MB each): It takes about 4 seconds per image, mostly in str2arrbuf. Apparently converting a file into an ArrayBuffer is really slow. before_perf

Performance after (loading those same 4 images): Each image is taking 100-200ms. The file is read as a string, and only part of it is converted into an ArrayBuffer when needed. after_perf