5 ms·
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
by londons_explore 6y ago
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.
- ResidentSleeper 6y agoI'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.
- 0-O-0 6y agoSignificant 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.
- stefan_ 6y agoStructure of arrays vs array of structures is in many ways identical code but a compiler can much easier optimize the former than the latter.
- alkonaut 6y agoIf 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.
- Kiro 6y agoWhat are you building that requires that?
- alkonaut 6y agoA 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.
- ngcc_hk 6y agoTotally 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!
- deleuze 6y agoIt'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.
- darepublic 6y agoI was indoctrinated with that in school. What, it is not true anymore?
- deleuze 6y agoYes! Much has changed. Here's a good summary: https://stackoverflow.com/questions/46512888/how-is-string-concatenation-implemented-in-java-9 https://stackoverflow.com/questions/46512888/how-is-string-c... The change in question is JEP 280.
- michielderhaeg 6y agoDon't quote me on this, but I think most String operations are compiled to StringBuilder operations automatically.