News for hackers. Stuff that matters.
Re:Memory in JavaScript – Beyond Leaks (2019) by londons_explore on Monday June 22, 2020 @05:10AM (#23598464)
Please don't do this.

Just write the code to describe what you really wanted to do, and if that performs badly, open a bug with V8 or other JavaScript engines to optimize it.

If there are two identical ways to write the same code, the engine is what should be deciding what's fastest and running that.

In this case, it probably ought to be pulling the "x" field out of this structure and doing a memset() on the whole thing.

Re:Memory in JavaScript – Beyond Leaks (2019) by ResidentSleeper on Monday June 22, 2020 @05:39AM (#23598595)
I'd be surprised to learn that there's any sensible optimization that the compiler/runtime can make to ensure optimal data locality. The problem is difficult enough that the entire Unity engine is being pretty much rewritten to make use of sequential memory access.

In addition, I really, really wish more JS developers actually cared to learn about optimization and about how the runtime/hardware actually works. We've "developed" the web to such a slow, buggy mess that I've given up on the idea that there's any way to fix it. I hope somebody figures out a way to start over, preferably with no scripting capability, because apparently giving people any half-baked scripting language results in them soon developing nuclear footguns with it.

Re:Memory in JavaScript – Beyond Leaks (2019) by 0-O-0 on Monday June 22, 2020 @06:09AM (#23598707)
Significant part of the web is fast and works just fine. Sure experience on major news and media sites sucks, but you have to realise that it's caused by their monetisation model and not a platform itself.
Re:Memory in JavaScript – Beyond Leaks (2019) by deleuze on Monday June 22, 2020 @10:34AM (#23600624)
It's also how you end up with cargo cult optimizations for things that may have been solved ages ago in the VM. I've met Java devs who still insist on using StringBuilder for everything without empirical evidence.
Re:Memory in JavaScript – Beyond Leaks (2019) by darepublic on Monday June 22, 2020 @10:47AM (#23600799)
I was indoctrinated with that in school. What, it is not true anymore?
Re:Memory in JavaScript – Beyond Leaks (2019) by deleuze on Monday June 22, 2020 @10:55AM (#23600890)
Yes! Much has changed. Here's a good summary: https://stackoverflow.com/questions/46512888/how-is-string-c...

The change in question is JEP 280.

Re:Memory in JavaScript – Beyond Leaks (2019) by michielderhaeg on Monday June 22, 2020 @10:56AM (#23600901)
Don't quote me on this, but I think most String operations are compiled to StringBuilder operations automatically.
Re:Memory in JavaScript – Beyond Leaks (2019) by alkonaut on Monday June 22, 2020 @06:24AM (#23598767)
If compilers could do this even with hours of time to spend, that would be absolutely revolutionary. I program in a high level language (C#) and my whole day is usually moving things to the stack instead of the heap, devirtualizing calls, making SoA/AoS changes etc. I doubt we'll ever be in a position where compilers can make these decisions well enough. Much less jit compilers and dynamic runtimes that need to do it with time constraints.
Re:Memory in JavaScript – Beyond Leaks (2019) by Kiro on Monday June 22, 2020 @06:44AM (#23598882)
What are you building that requires that?
Re:Memory in JavaScript – Beyond Leaks (2019) by alkonaut on Monday June 22, 2020 @08:59AM (#23599651)
A large desktop app (CAD). But the same thing has popped up in other projects: games, audio plugins, statistics, visualization... Basically anything that is CPU/Memory bound (which is most things except for basic web/database apps I find) needs careful thinking around performance.
Re:Memory in JavaScript – Beyond Leaks (2019) by stefan_ on Monday June 22, 2020 @06:19AM (#23598747)
Structure of arrays vs array of structures is in many ways identical code but a compiler can much easier optimize the former than the latter.
Re:Memory in JavaScript – Beyond Leaks (2019) by ngcc_hk on Monday June 22, 2020 @07:21AM (#23599051)
Totally agreed; try to do that for C++ before Java is popular. The maintenance guy would love you for the saving of time.

Optimise after. BTW, I thought it is about memory leak which is seriously not performance tuning!