Has PGO for (re)compiling methods been considered?

It just crossed my mind that it would be very nice if Julia provided some kind of profile-guided optimization (PGO) API.

Something like:

  1. The user gathers a performance profile for some of their Julia code

  2. The user is now able to request a recompilation of their Julia code, feeding the profile to the Julia compiler to enable better optimizations, like, for example, control height reduction or hot-cold splitting.

Step 2 could look like this:

pgo_anonymous_function = recompile_with_pgo(my_function, (ArgType1, ArgType2, ...), my_profile)

# Now `pgo_anonymous_function` may be used as a more performant version of `my_function`!

The nice thing (I think) is that LLVM already supports PGO, so I guess this would mostly be a matter of expanding the profiling functionality and plugging into LLVM, and then just letting LLVM take care of the optimization?

Has this been considered already? Is it really such a low-hanging fruit like it seems? Perhaps this could even be implemented as a package outside the standard library?

Do you know about Catwalk.jl? It targets another type of optimizations than what you mention (namely, it optimizes dynamic dispatch) and is currently designed more as a JIT kind of thing, but I think the approach it takes could very well be reused in a PGO context.

3 Likes

The linked PR is a different topic, it’s about compiling Julia itself (the implementation), while I’m talking about compiling user Julia code.

There are some tools for a related analysis: Profile-guided despecialization · SnoopCompile

The aim there, though, is to figure out what isn’t worth optimizing, given that Julia optimizes everything by default.

2 Likes

I mean, that affects the Julia compiler