I have been profiling a lot of javascript today in writing a firefox js engine bug report, and started really noticing the slight differences between JIT compilations. While there are some obvious things that could cause non-deterministic flagging of hot sections of code (for example, inlining or not inlining a function that is called a random number of times), I was wondering if external fluctuations of execution speed (like CPU throttling) could cause non-deterministic JIT compilation?
Can JIT compilation be non-deterministic?
javascript;jit;compilation
There are many ways in which JIT compilation can be non-deterministic. For example:if the JIT runs on a separate thread, depending on OS scheduling, during one run, the JIT may be scheduled first, and compile a certain function before it runs, whereas on a different run, the interpreter may be scheduled first, and run the function before it is compiledif the JIT uses dynamic profiling information for optimization, and the profiler is a sampling profiler, then even tiniest fluctuations in timing, memory layout, etc. may cause the sampling to occur at different points of the execution, possibly leading to different resultsthe more aggressive the optimizations, the more CPU time and memory the JIT compiler needs. If the system is low on memory, for example, a JIT compiler may decide to disable some optimizations, or only enable them for a few very high value targets (i.e. very hot spots)