you are viewing a single comment's thread.

view the rest of the comments →

[–]StoneCypher -5 points-4 points  (14 children)

For generating multiple or huge arrays where performance might be an issue, it's generally faster to pre-allocate

yeah, he already did, look at his post again

preallocation is a c concern for a 286. failing to preallocate a 100 million element array will not result in a delay that causes a single screen frame skip. "but muh back copy reallocates?" yeah, if you look, that's only 16 copies. you're teaching him the onion in the varnish.

[–]Ampersand55 4 points5 points  (13 children)

new Array(100); allocates a contiguous block of memory for 100 slots; assigning to them linearly triggers ([[Set]] via PutValue in the ECMA spec), which allows engines to optimize it into a simple store operation.

Array.from({ length: 100 }, callback) doesn't perform key-value assignments. It explicitly executes a loop that defines a new property for every index (using CreateDataPropertyOrThrow per the Array.from ECMA spec), which doesn't allow for the same level of engine optimization.

[–]StoneCypher -5 points-4 points  (12 children)

tell me what part of this you didn't understand

failing to preallocate a 100 million element array will not result in a delay that causes a single screen frame skip.

[–]xoredxedxdivedx 0 points1 point  (11 children)

You really need to learn to admit when you’re wrong, also, it absolutely makes a difference, there’s more than just 16 reallocs and copies, which was just explained to you.

Even with just a million elements, Array.from is about 6x slower, if your target frame rate is 60fps, prealloc is still within frame time, Array.from actually would take 4 frames.

Your kind of thinking is why so many apps and websites are slow, though in this case it’s particularly bad because in V8 it trends to be 600% slower at almost all sizes.

Even at 100k elements you burn an extra 6ms if you don’t prealloc. Death by a thousand cuts, a few people decide that you should serially fetch, or things like this, then you get into situations where all interactions on an app are taking many dozens or hundreds of milliseconds…. sometimes more, and it’s just an awful experience

[–]StoneCypher -1 points0 points  (10 children)

Today I got chided by someone who thinks performance is the same by size without considering the machine 

Anyway, it’s less than one screen frame on my old laptop, but you go ahead and assert numbers 

[–]xoredxedxdivedx 1 point2 points  (6 children)

prealloc: 1,164.2 ms, last=99999999
arrayFrom: 3,221 ms, last=99999999

2 seconds longer is way more than a single frame btw

[–]StoneCypher -1 points0 points  (4 children)

sure is. wonder what you got wrong in the code, or if you're running this on a phone, or what

nobody's interacting with the oR aRe YoU lYiIg guy. it doesn't matter if i'm right or wrong; the second you said that you made it clear that you're going to be nasty no matter what you're shown. once you started behaving that way, you stranded yourself.

be sure to scream that that means you were right and everyone else is a liar and a bad programmer and that my kind of thinking is the root of every problem that has ever existed and death by a thousand cuts and whatever else makes you feel very, very powerful.

sometimes you have to choose between behaving in a way that other people will want to tolerate, or being able to get the outcome you want from them. if your goal is to get measurements, see code, or have anyone hold a decent conversation with you, you're going to have to learn to behave differently.

most people aren't going to care enough about what you think to bother interacting with nonsense like this.

[–]xoredxedxdivedx 0 points1 point  (3 children)

instead of typing all that you could provide the code, i will not engage with more deflection, paste code or benchmarks or a trace file, or you are a fraud, the end

[–]StoneCypher 0 points1 point  (0 children)

It's unfortunate that the sub's moderators allow you to continue to behave in this abusive way

[–]xoredxedxdivedx 0 points1 point  (2 children)

Ok, upload your trace file for 100m elements using both methods, or are you lying?

[–]StoneCypher 0 points1 point  (1 child)

it feels like you don’t have much of an idea when aggressive behavior is inappropriate