var allocations = []
function allocate_ram(batches, bytes) {
for (var i = 0; i < batches; i++) {
allocations += [new Uint8Array(bytes)]
}
}
allocate_ram(512, 1024*1024)
window.parent.postMessage("allocated", "*")
console.log("Allocated")
That’s half a gigabyte, plus a lot of bookkeeping. Also creating a Uint8Array may not actually allocate the memory—in Firefox at least, new Uint8Array(1e9) (an actual gigabyte) is fast and uses no memory, then accessing it for the first time is the slow operation because it does the actual allocation/initialisation.
And why is it done in an iframe? Was it supposed to be a Worker to take it off the main thread? Or even just as simple as poor man’s async/callback?
Was it done so to make it thrash your CPU for a bit as well as your RAM, to make it take longer?
Are these the reasons why it was done in a million tiny arrays rather than one proper-sized one, and in a misguided/failed attempt to avoid blocking?
I think you should get similar results from replacing the entire iframe code with
(async()=>{
new Uint8Array(1e9)[0];
spinner.innerHTML="Thanks! ✅"
})();
Or perhaps setTimeout(…) instead of (async …)(), I find I can’t remember whether an async IIFE gets started immediately or put into a microtask, and I’m too lazy to check. Or the exact interactions with rendering, even if it is microtasked… hmm, yeah, better go setTimeout I think.
They're definitely doing that so if you're watch your free memory you see it slowly ticking down as the loading wheel progresses, instead of it just immediately dropping in a gigabyte chunk.
It's not like it's a functional program that's actually doing anything (with the memory or otherwise), I think it's justified to be weird and illogical if it makes the effect "feel right". In the same way that Hollywood hacking scenes can have big "you've been hacked!" popups, as a treat
lobo | a day ago
i was hoping it would be executed to the extent it is and i am so happy it is
pyj | a day ago
This is a flip on a classic.
One place I worked at had a running joke to “make sure you download additional ram.”
chrismorgan | a day ago
The technique this uses to allocate each “gigabyte” is bizarre. In an invisibleish iframe:
That’s half a gigabyte, plus a lot of bookkeeping. Also creating a
Uint8Arraymay not actually allocate the memory—in Firefox at least,new Uint8Array(1e9)(an actual gigabyte) is fast and uses no memory, then accessing it for the first time is the slow operation because it does the actual allocation/initialisation.And why is it done in an iframe? Was it supposed to be a Worker to take it off the main thread? Or even just as simple as poor man’s async/callback?
Was it done so to make it thrash your CPU for a bit as well as your RAM, to make it take longer?
Are these the reasons why it was done in a million tiny arrays rather than one proper-sized one, and in a misguided/failed attempt to avoid blocking?
I think you should get similar results from replacing the entire iframe code with
Or perhaps
setTimeout(…)instead of(async …)(), I find I can’t remember whether an async IIFE gets started immediately or put into a microtask, and I’m too lazy to check. Or the exact interactions with rendering, even if it is microtasked… hmm, yeah, better gosetTimeoutI think.nytpu | a day ago
They're definitely doing that so if you're watch your free memory you see it slowly ticking down as the loading wheel progresses, instead of it just immediately dropping in a gigabyte chunk.
It's not like it's a functional program that's actually doing anything (with the memory or otherwise), I think it's justified to be weird and illogical if it makes the effect "feel right". In the same way that Hollywood hacking scenes can have big "you've been hacked!" popups, as a treat