Nested QuadGK: Long compilation time gets short when plotting the argument beforehand, but not when calling it

I don’t have an explanation for the compilation time — you might file an issue at JuliaLang/julia — but I would strongly recommend against using nested 1d adaptive quadrature, which can easily waste a lot of time trying to refine 1d integrals in regions that don’t contribute much to the overall integral.

Instead, you should use a “cubature” routine (like in HCubature.jl, Cubature.jl, or Cuba.jl) that knows how to do multiple integrals in a holistic way. Even though these routines typically integrate over box domains, you can integrate over other domains with a change of variables. For example, your problem is a triangular domain, which can be mapped to a box with:

\int_0^1 dx \int_0^x dy \, F(x,y) = \int_0^1 dx \int_0^1 du \, xF(x,ux)

via the change of variables y = ux.

5 Likes