[RFC] Ideas for tools around type stability / optimization

When optimizing slow code, people, especially newcomers, are pointed to tools like @code_warntype and profilers like ProfileView. I wanted to collect some ideas for improvement because I think some steps could be made easier or more automated. Here are some of my ideas, I hope that not too many have been discussed elsewhere, I didn’t find much at least.

  1. A function called check_typestable that takes an expression and returns a tree structure in which for every sub function call there is a Boolean indicating whether it’s type stable or not (by that I mean no red in the usual @code_warntype output). Why do @code_warntype and scan the large output if I can first skim if there’s a problem at all? This could also be a nice thing to check for in tests so that there are no regressions. @code_warntype doesn’t return anything as far as I can see, would be nice to have a datastructure to further process.

  2. Optional formatted HTML output for all @code_ macros. I know that many people love the simplicity of the REPL but there is only so much you can do with static text output. If we could think of interactive interfaces that would let people fold or expand certain long type signatures for example, or lower the visual saliency of all this %1 = stuff that’s obstructing the more important information. Imagine replacing every complex type with a “legend” marker and having a legend on the side for example, that could help getting a quicker overview.

  3. Combining Profiler output with type stability information. It would be great if for every flame graph entry there was also information on the profiled functions so that it would be easier to reach conclusions where optimizations could be most effective. I think that’s a quite manual process now, look at line numbers, check function, maybe run that with @code_warntype, etc.

I would actually like to contribute to something like 2, are there already efforts underway, maybe in Juno? The stack traces there are for example already more readable than in the REPL, so they have the right idea.


Related in some way:

I totally support that. Maybe creating an struct that holds the info is better than raw text

You may also be interested in:


Oh that looks nice, I’ll have a look. Haven’t seen that mentioned anywhere so far