Case Study: Method Invalidations caused by Pkg.jl with Julia 1.11

One could also consider a deeper root cause to be the combination of:

  1. People don’t write type-stable code consistently. If the authors of Pkg - presumably seasoned Julia core devs - doesn’t create type-stable code, it’s hard to have hope that the broader ecosystem will be type-stable
  2. Type unstable code is prone to invalidations from third-party code. This is due to compiler optimisations that try to regain performance from some type-unstable code

I fear the only reasonable solution to this problem is to remove the compiler optimisations mentioned in 2. If we don’t, we’re going to play invalidation whack-a-mole until the end of time, while also living with the fact that invalidations will continue to be rampant in the wider ecosystem - see e.g. this post where a single package causes 66,000 invalidations.

Also, having the optimisations in 2. defeats the idea that Julia devs can strategically choose to write type-unstable code where performance is not important. This is not actually a possibility if type instability across any larger piece of code causes uncontrollable invalidation and latency, even for code that is not performance sensitive.

10 Likes