Making use of `optlevel` etc

The Makie ecosystem still suffers from large compilation latency. Tim Holy has kindly been looking at invalidations for us, but that is relatively slow work and hard to do for the amount of code that is there. One option we could try is using the relatively new @optlevel macro. But this only allows setting one level per module. There is a hierarchy of functions in AbstractPlotting, some of which definitely need to be optimized, others probably not much or not at all. Is there any way to achieve that, short of reorganizing everything and forcing different code into modules just for this?

The hierarchy is something comparable to the following:

# called less often, less optimization needed
top-level plotting functions
plot objects
.
.
.
low-level objects
projection math
backend interface code
# called more often, more optimization needed

I suspect that a lot of time is spent optimizing / compiling / inferring top to medium level functions, even though the cost of calling these is very small compared to all the low-level functions that do the interesting stuff. Any advice on how to disentangle these and spend the least amount of processing power on unnecessary optimizations?

Ideally, I’d want to “pythonize” the top level stuff, it can be inefficient for all I care, if it gets the startup time down.

You can try adding @nospecialize at top level, which should apply until disabled:

@nospecialize

function slow(x) ... end

@specialize

function fast(x,y) ... end