3 ms·
Your talks always frighten me when it comes to VM's. I just want predictable performance- is that too much to ask? (Semi-serious question). edit: to clarify. I
by randomfool 11y ago
Your talks always frighten me when it comes to VM's. I just want predictable performance- is that too much to ask? (Semi-serious question).
edit: to clarify. In C++ I write dumb but readable code knowing that the compiler will always perform specific optimizations. In JS it seems that there are many factors resulting in different optimization levels. How do I ensure that the VM does not execute my 'dumb but readable' code literally? Without that guarantee it seems that I have to frequently resort to optimized yet unreadable code.
- mraleph 11y agoI obviously craft/collect examples of V8 going off the rails for these talks just to show that VMs are software and all software has bugs --- and those bugs don't necessarily manifest as crashes and incorrect results - they can lead to worse performance and developers must be ready for this: must be ready to diagnose these issues, report them and work around them. For a single test case where V8 goes off the rails there are millions of lines of code across the globe which V8 optimizes correctly. On a funny note: I actually do have a version of this talk where I show GCC going slightly of the rails and producing a code that is 3 times slower than it should be because it hits an (infamous) partial register dependency stall --- see StackOverflow question[1] for the gory details. > How do I ensure that the VM does not execute my 'dumb but readable' code literally? Well, as I do say in the talk: reasonable code should be reasonably fast. If it is not the case --- file bugs with VM vendors. Keeping your code relatively static / monomorphic is the best way to achive performance in any language. In any case I think it's much much much more important to optimize algorithms not their concrete implementations. [1] http://stackoverflow.com/questions/26585977/64-bit-code-generated-by-gcc-is-3-times-slower-than-32-bit/26588074#26588074 http://stackoverflow.com/questions/26585977/64-bit-code-gene...
- vardump 11y agoC++ performance is a true minefield between different compilers and their versions. For example, fail to provide correct incantation of compiler flags or do something in code that confuses auto-vectorization, and your performance can suffer by an order of magnitude. I guess a lot of Javascript micro-optimization comes down to don't change field type and give type hints in assignments. Like: var integerType = 0|0; integerType = 45|0; integerType = (integerType + 1)|0; That '|0' tells the Javascript VM that you have integer as real data type. If you'd suddenly assign 'integerType = 5.1;' or 'integerType = "string";', the built in guards would make the JIT compiled native code to fail and the Javascript engine would fall back to interpreting. Emscripten can be used to compile C++ into Javascript. Perhaps it could help you?