Zero-Overhead Metaprogramming
stefan-marr.de
stefan-marr.de
It is very practical for a program to write a Java class, compile it, then load the classfile, thus the metaprogrammed object runs as fast as anything in Java.
Hold on. That might well be true for dynamic reflection. But metaprogramming is a wide term. It seems simple enough to give an example of metaprogramming that comes at no runtime cost: compile-time metaprogramming.
Kiselyov has a catchy term for one approach to compile-time metaprogramming: "Abstraction without guilt".
Too bad that they didn't do it in the article, then. I guess it isn't "common wisdom" enough.
The main point of the paper is to show that runtime metaprogramming can be optimized with a classic JIT-compilation technique. After one sees it, it's kind of trivial, but it isn't done in common VMs.
Don't be disingenuous in the process.
I see you've changed the opening "Metaprogramming" to "Runtime metaprogramming", which is better IMO.
Yeah, but there is a reason for that... It turns out to be less useful than you think, and altering language semantics in a meaningful way hampers the ability for an optimizer to make code execute efficiently (without the language's semantics, you really can't make assumptions).
> MOP needs to be severely restricted and for instance metaobjects cannot change at runtime..
True as far as it goes, but to the extent that they can change, the performance penalty is there because you can't resolve issues at compile time. There are a variety of tricks employed to get you a hybrid model, where you effectively have a JIT optimize after dynamic binding, but if you truly have mutating metaobjects, there is an undeniable cost that you can't get around (and the benefits really aren't that huge).
So, in the end, you get a powerful MOP without reflective overhead.
...which results in a scenario no different in terms of overhead or expressiveness, than you'd have with a static MOP with runtime dispatch.
And, what do you mean with runtime dispatch? Static and runtime dispatch combined? I am not sure I really know what you got in mind.
With dispatch chains, the runtime dispatch is resolved at runtime and the JIT compiler can inline through it. But, you need that runtime information. A static compiler, like for OpenC++ can't usually do that.