[erlang-questions] At what point am I "playing compiler"

Thomas Lindgren <>
Mon May 18 13:45:27 CEST 2009






----- Original Message ----
> Not knowing anything about compiler design: Would it be possible to add  
> "compiler notes" to the existing module so that the compiler could do 
> these optimisations? This would avoid growing the core which could lead 
> to feature creep style growth of the core languge - Where do you draw 
> the line? The other advantage is that it would allow third parties to 
> make recommendations to the compiler for their modules to optimiser the 
> compiled code. It could also allow a larger group of people to play with 
> optimising things different ways without having to play directly with 
> the compiler. Admittedly, this may be a very small group.


The basic problem here is hot code loading. Some years ago, I worked on some solutions to cross-module optimization, which at least showed that there was some juice in the idea; I know some Java compilers do lots of clever reoptimization when code is loaded. However, such a compiler needs a lot of work and there doesn't seem to be manpower to make that sort of effort, so a simpler approach might be that we could just designate more modules as "preloaded". 

This approach relies on how preloaded modules behave in Erlang/OTP, which is somewhat obscure and not really part of the language, but essentially straightforward. Preloaded modules are compiled into the VM runtime today at VM build time, so no way to change the code on the fly there. A compiler can thus assume any modules marked as preloaded are fixed and available for optimization. The code of the preloaded modules would have to be known at compile-time, and the compiler would have to be aware of how to optimize calls to these modules. (And you might get into trouble by cross-compiling between systems with different sets of preloadeds.)

Best,
Thomas



      




More information about the erlang-questions mailing list