Capturing "sub" dependencies during precompilation

I have a package X which depends on Y which depends on Z. Z is not a direct dependency of X, and Y is done by a “third-party”, so I can’t influence it.

I’m using some example code @compile_workload, but still see a lot of compile statements when running the same code after loading X during usage. I’ve managed to “fake compile” these calls by observing them with --trace-compile and then doing

Z = Y.Z

precompile(...)

where precompile(...) is some captured compilation statement that involves Z. This seems to improve TTFX for me by quite some bit, but it feels hacky. What would be the correct way to approach this?