Taking TTFX seriously: Can we make common packages faster to load and use

Thanks, that’s helpful! We only use static arrays for points and matrices in R^3, and the part of the code that takes a large TTFX is not the one that uses them, so I don’t think that’s the issue.

Maybe we can turn this discussion into a crowdsourced list of tips, and put that in a pinned thread or something? Here’s what I’ve gotten from this discussion, feel free to correct or add to it.

Don’t use large StaticArrays

https://github.com/trixi-framework/Trixi.jl/issues/516

Don’t use Requires

Enclosed code cannot be precompiled.

Careful about type instabilities

(this one is not clear to me)

Trigger precompilation in your package module

Call functions that don’t have a side effect. Use precompile on those that do. Info on the internet about __precompile__ is outdated, don’t use it.

Avoid invalidations

Profile your first run

Sometimes you get useful information out of it. SnoopCompile also gives a potentially more helpful view.

Use @nospecialize to disable inference of a particular argument

“use it when a function is called multiple times with different argument types, compiling that function is expensive but specialising on argument types does not have a significant impact on run-time performance” When should we use `@nospecialize`?

16 Likes