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

**URL:** <https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949>\
**Category:** Performance\
**Tags:** ttfp\
**Created:** [January 20, 2022, 5:16pm UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949 "2022-01-20T17:16:03Z")\
**Posts on this page:** 1\
**Showing post:** 84

<div class="post-metadata">

**Author:** ![antoine-levitt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/antoine-levitt/32/4008_2.png) [@antoine-levitt](https://discourse.julialang.org/u/antoine-levitt)\
**Post date:** [January 27, 2022, 8:34am UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949/84 "2022-01-27T08:34:14Z")

</div>

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>
>
> I am observing that the startup time (time for setting up ODE and time for setti…ng up solve) scales very strongly with polydeg. Instead of a second for the KHI when using N=3, it takes a couple of seconds for N=7 and a couple of minutes for N=15 (while keeping the total number of DOF equal, i.e. reducing the grid level). 
> 
> Any idea what is going on?

# 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

> **[Tools for analyzing and fixing invalidations - Analyzing sources of compiler...](https://julialang.org/blog/2020/08/invalidations/#tools_for_analyzing_and_fixing_invalidations)**
>
> Julia runs fast, but suffers from latency due to compilation. This post analyzes one source of excess compilation, tools for detecting and eliminating its causes, and the impact this effort has had on latency.

# 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`?](https://discourse.julialang.org/t/when-should-we-use-nospecialize/10392)

---

_[View the full topic](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949)._
