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.
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.
response.response
is really slow after loading the file, so instead useresponse.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.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.