Documentation on JIT compiler?
Mostra commenti meno recenti
Can someone explain the workflow of the JIT compiler? I am interested in basic functionality. When is compiled code saved, what causes it to be deleted, and what causes it to be recompiled.
I read somewhere that changing directories forces a reset of previously compiled code, but I couldn't find any documentation explaining this.
My goal is to write maximally optimized code. Another Q - I've also noticed that a large software package opens faster the second time I open matlab, suggesting that JIT compiled code "lingers" even after closing and reopening matlab. Is this true?
7 Commenti
John D'Errico
il 15 Nov 2018
Don't. That is, don't make any assumptions about what goes on under the hood there. Maximally optimized code won't necessarily be so next year anyway. And maximally optimized code would be CPU & system dependent. It would be problem dependent, because problems of different sizes might involve differing tricks to be truly optimal.
Even something as simple as a matrix*matrix multiply has been shown to be non-obvious. For example, carefully time how long a matrix*matrix multiply takes, then plot the time required as a function of the order of the matrix. For nxn matrices, this should be an O(n^3) problem, scaling smoothly, because your CPU will just pump those adds and multiplies through as fast as it can. And we can count just how many such ops are needed. But various factors conspire here, from the blas to cache size, etc. So what happens is that curve of time versus order is not a smooth one, even after you reduce the noise by replication. The bumps will be system dependent, and consistent, but they will also potentially change with release, nor should you bother to try to find some subtle tweak to avoid them.
Spending a lot of time to chase subtle features in JIT is a waste of time. Instead, spend that time to profile your code if there are bottlenecks. Then spend time to either alleviate those specific identified bottlenecks, or just move on and accept tham.
Andrew Landau
il 15 Nov 2018
per isakson
il 15 Nov 2018
Andrew Landau
il 15 Nov 2018
Modificato: per isakson
il 17 Set 2019
Walter Roberson
il 15 Nov 2018
The blog entries are the only "actual documentation", aside from a couple of lines here and there in the Release Notes. The detailed workings of JIT is pretty much proprietary.
Andrew Landau
il 15 Nov 2018
"I want to see actual documentation that explains how JIT compiling works in matlab!"
You are very unlikely to get it, for the reasons that John D'Errico has already explained. The TMW blogs have mentioned this several times, e.g. "We recommend not writing specifically for the JIT since the JIT is constantly evolving. You should though keep in mind the general good MATLAB-coding practices, such as those listed above"
and made it clear that code should not be written around JIT enhancements: "Keep your code natural. Don't write unnatural code just to take advantage of this."
See also:
"However, if you look at matlab documentation, the number of people who say "don't use 'clear'" is high. The reason is so that you don't force the engine to recompile code. Now, according to your advice, this shouldn't matter. "
Unlike the behavior of the JIT engine, the behavior of clear all is quite well documented, as are the multiple sources in the documentation that recommend avoiding clear all because it forces code to be recompiled. So that is a rather apples-with-oranges kind of comparison.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Introduction to Installation and Licensing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!