JuliaOpt/JuMP.jl — pull request #271 by mlubin (2014-09-25 04:23:19+00:00)
Title: WIP: Rewrite macros using staged functions

Major revamp of expression parsing macros using staged functions (requires Julia 0.4).
Primary new feature is that this lets us handle commutivity (#99) without sacrificing performance, and also we'll get faster quadratic expression building.

Before:
```
$ julia speed.jl
PMEDIAN BUILD MIN=0.311928322 MED=0.330600015
PMEDIAN WRITE MIN=1.731297123 MED=1.751828376
CONT5 BUILD MIN=0.179188774 MED=0.216120392
CONT5 WRITE MIN=1.45397678 MED=1.47033628
```
After:
```
$ julia0.4 speed.jl
PMEDIAN BUILD MIN=0.329470738 MED=0.332986915
PMEDIAN WRITE MIN=5.201167811 MED=5.25195727
CONT5 BUILD MIN=0.232650668 MED=0.237446502
CONT5 WRITE MIN=3.984346782 MED=3.994990259
```

So 5% slowdown for PMEDIAN build time, and 30% slowdown in CONT5 build time. This is a reasonable trade off for the extra flexibility, I think. I can do a bit more tweaking to see if I can get extra speed ups, and we can expect improvements in compiler optimizations for staged functions. Slow down in write time is unrelated, should investigate separately what's causing this in Julia 0.4.

Generated code is a bit more type stable now, since new intermediate variables are created for the output of each subexpression.

TODO:
- [ ] Improved handling to speed up quadratic expressions (requires quadratic benchmarks)
- [ ] Speed tweaks
- [ ] Decide what to do about Julia 0.3 compatibility