3 ms·
is there a way to signal to the browser that I'd like all of my JavaScript to be compiled as best as possible and that I don't mind my users waiting while this
by crucio 14y ago
is there a way to signal to the browser that I'd like all of my JavaScript to be compiled as best as possible and that I don't mind my users waiting while this happens? Could this be useful for complex games where start-up speed may not be deemed as important as runtime performance?
- shardling 14y agoIn a sense that's what asm.js is. Obviously not quite what you're asking for, though.
- jomohke 14y agoIf you compiled immediately you would probably find that your games performed much worse, because the compiler would have very little information about the functions and the kind of arguments that will be passed to them. Once a function has run many times, the compiler can use the gathered statistics (such as knowing that the arguments were always floats) to produce better optimised machine code (such as using float-specific ops, and eliminating code paths that expect arguments other than floats). This is a common tradeoff for all JITs; Should I wait longer to produce better code, or compile sooner to run the faster code earlier? You can play with this number in most Java JVMs (OpenJDK or Sun/Oracle) using the argument "-XX:CompileThreshold". This sets how many times a function should run before it is compiled. It defaults to about 1500 for a client VM and 10000 for a server VM. As mentioned in a sibling comment, asm.js is a partial alternative to this tradeoff, as your asm.js code specifies all data types ahead of time, and hence they can be compiled up-front fairly well.