5 ms·
PixiJS is the only one to reach above 100 FPS on my desktop, though that's inbetween frequent GC pauses. Two.js gets ~70 and Paper.js gets ~48. There would pro
by negativegate 6y ago
PixiJS is the only one to reach above 100 FPS on my desktop, though that's inbetween frequent GC pauses. Two.js gets ~70 and Paper.js gets ~48.
There would probably be less GC pauses if the benchmark code wasn't doing things like
[...Array(this.count.value).keys()].forEach(...)
instead of a for loop.
- ncr100 6y agohttps://news.ycombinator.com/item?id=23084576 https://news.ycombinator.com/item?id=23084576 see
- gnykka 6y agoGood point. Usually I like to use map or reduce for arrays but here simple for is easier.
- gnykka 6y agoI made a change to loops to use for() cycle, thanks
- bartread 6y agoI see people doing this crap all the time in the middle of tight loops that do a lot of work in C#, JS, TypeScript, and justifying it on the grounds of "productivity" and "readability". It seriously gets on my nerves. Do not do this. Functional code might look nice but often creates excess work for the GC and kills performance. We had a situation within the last week where a piece of code was blowing through 350MB of memory unnecessarily, and massively slowing down a heavy set of calculations, because of exactly this kind of issue.
- johnfn 6y ago> ustifying it on the grounds of "productivity" and "readability". It seriously gets on my nerves. Do not do this. On the contrary, please do this. "productivity" and "readability" are important aspects to consider when writing code, especially if someone else is going to be reading it. When you've identified a bottleneck, feel free to write the code in the bottleneck more performantly, if necessary. But please do not sacrifice readability across the entire codebase for a couple of hot loops.
- hombre_fatal 6y agoI can agree with your point in general, but [...Array(N).keys()].forEach() is not the most readable way to write "do this N times". It creates an array of length N, but for obscure-to-most-people reasons, Array(N).forEach() doesn't work, so they Rube Goldberged their way to an array that they could call forEach() on. Their solution was to use Array#keys to get an iterable from the array. But an iterable doesn't have a .forEach() method, so they iterate the iterable into another array just to iterate it again with Array#forEach. Frankly the only thing this seems optimized for is to solve the problem without the for-loop for some reason. The for-loop, on the other hand, is an instantly obvious solution. It's how programmers have been expressing "do this N times" for decades across languages.
- akiselev 6y agoEspecially when Array(N).fill(0).forEach((_, key) => ...) gives you the same exact functionality without the second eager array if you're seriously trying to avoid for loops.
- hombre_fatal 6y agoArray.from({ length: N }).forEach()
- Aeolun 6y agofor(var i = 0; i < N; i++) {}
- chii 6y agoThis is the best and cleanest way. Unless there's a reason to use Array.forEach such as automatic paralellization or some other SIMD-like optimization that can be done that cannot be done in a forloop. A lot of cargo-cult programming seem to take functional programming to mean programming using the map/reduce/foreach functions, and you end up with shitty code like [...Array(N).keys()].foreach(), just so you can somehow claim that you're doing functional programming.
- Aeolun 6y agoIs that really readable? I may be a crusty old fart, but that kind of shit is the antithesis of readable to me.
- Fr33maan 6y agoSir, I have to upvote you