# 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:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [January 24, 2022, 5:45pm UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949/48 "2022-01-24T17:45:02Z")

</div>

Split this topic on January 24, 2022, 5:45pm UTC

A post was merged into an existing topic: [Why isn’t `size` always inferred to be an Integer?](https://discourse.julialang.org/t/why-isnt-size-always-inferred-to-be-an-integer/75139/11)

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [January 24, 2022, 5:49pm UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949/49 "2022-01-24T17:49:38Z")

</div>

You actually want to time and/or profile the first run. So start a fresh session, and:

```julia
using ProfileView
@profile @time using SomePackage
ProfileView.view()
@profview @time themainfunction(x)

```

Although profiling slows things down a bit. I also found ProfileView struggles with really huge load times and just `@profile` can be better. From that you can spot obvious problems, what code and packages actually take time to load, etc.

Edit:

And also to look at the functions taking inference time:

```julia
using SnoopCompile
tinf = @snoopi_deep themainfunction(x)
fg = flamegraph(tinf)
ProfileView.view(fg)

```

Then:

```julia
using Cthulhu
@descend themainfunction(x)

```

And look around to find the unstable (red) bits that looked slow to load in ProfileView, and anything else that seemed like a problem. Im sure there are more sophisticated ways to do this, but it gets you a long way.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [January 24, 2022, 5:51pm UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949/50 "2022-01-24T17:51:49Z")

</div>

> [@Raf](#):
>
> You actually want to time and profile the first run. So start a fresh session, and:

I had understood that this can profile the compilation _of the profiler_ as well. Doesn’t it?

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [January 24, 2022, 5:55pm UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949/51 "2022-01-24T17:55:23Z")

</div>

I assumed `@profile` was compiled in the base Julia image.

---

<div class="post-metadata">

**Author:** ![sairus7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sairus7/32/10816_2.png) [@sairus7](https://discourse.julialang.org/u/sairus7)\
**Post date:** [January 24, 2022, 7:06pm UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949/52 "2022-01-24T19:06:13Z")

</div>

As a developer not very familiar with the subject “what should I write additionally to use my packages faster”, it would be nice if I have just a simple build flag that says “just precompile this package from all of its own tests, and don’t care the excessive code”.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [January 24, 2022, 8:07pm UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949/53 "2022-01-24T20:07:34Z")

</div>

> [@sairus7](#):
>
> “just precompile this package from all of its own tests, and don’t care the excessive code

Don’t know how realistic is this, but definitely a good idea.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [January 24, 2022, 11:18pm UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949/54 "2022-01-24T23:18:01Z")

</div>

This is the prof view for FinEtools.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/d/4d7097ec9bac7fe93c25d872fe36d97e82769491.png)  
So I think this is telling me that either I get rid of abstract types, or live with the `using` time of 15 seconds. The big block in the middle is all type inference…

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 24, 2022, 11:32pm UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949/55 "2022-01-24T23:32:02Z")

</div>

> [@PetrKryslUCSD](#):
>
> The big block in the middle is all type inference…

Did you try to force precompilation of that piece?

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [January 24, 2022, 11:35pm UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949/56 "2022-01-24T23:35:36Z")

</div>

If you are asking do I have ` __precompile__ (true)` in the top module, the answer is yes; otherwise, if you mean do I have targeted instructions in the code, the answers no.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 24, 2022, 11:44pm UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949/57 "2022-01-24T23:44:15Z")

</div>

Try calling that code at `using` time and see if it can precompile.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [January 24, 2022, 11:46pm UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949/58 "2022-01-24T23:46:25Z")

</div>

Sorry: which code?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 24, 2022, 11:52pm UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949/59 "2022-01-24T23:52:06Z")

</div>

The function the profile is pointing to.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [January 24, 2022, 11:53pm UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949/60 "2022-01-24T23:53:49Z")

</div>

Sorry about the confusion: I did

```julia
using ProfileView
@profview @time FinEtools

```

There is no “main” function per se.

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [January 25, 2022, 1:58am UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949/61 "2022-01-25T01:58:14Z")

</div>

@PetrKryslUCSD that large block isn’t your package code at all, but the `@require` block in ArrayInterface.jl. If you hover over the red lines near the bottom of the block you will find the requires calls.

This has me worried about my ArrayInterface deps now… we really need to stop using Requires.jl and get precompiled glue packages in Base.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [January 25, 2022, 1:59am UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949/62 "2022-01-25T01:59:36Z")

</div>

I know. Thanks! Which was really what prompted my question: if I use any abstract types, such as the arrays, there’s nothing I can do?

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [January 25, 2022, 2:03am UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949/63 "2022-01-25T02:03:35Z")

</div>

Abstract types are fine! Your package code takes no time at all.

The problem is you are using something that uses ArrayInterface.jl and also something in its Requires.jl block, so when your package loads the `@require` macro code also loads, and that has to precompile from scratch.

Probably your LoopVectorisation.jl dependency is causing all of that load time, because it depends on ArrayInterface.jl.

Yep. It’s all just LoopVectorization.jl. Profile for `using LoopVectorization` :

 ![2022-01-25-040114_1920x1080_scrot](https://global.discourse-cdn.com/julialang/original/3X/f/c/fc84a7765152379adaa2f98bfc01aadb1fb37b58.png)

@Elrod any idea whats going on here? I cant get ArrayInterface/Requires to do this with other packages.

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [January 25, 2022, 3:06am UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949/64 "2022-01-25T03:06:16Z")

</div>

What was it you’re profiling there?  
I am aware that LoopVectorization causes TTFX issues in several ways. One of the motivations for rewriting it with a totally different approach.

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [January 25, 2022, 3:08am UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949/65 "2022-01-25T03:08:39Z")

</div>

That’s just `using LoopVectorization`. But I found out about it from `using FinEtools`, where it appears that the `@require` code in ArrayInterface is actually taking all that time, if you look through the red lines in the stack of calls you can see that in LoopVectorization as well.

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [January 25, 2022, 3:11am UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949/66 "2022-01-25T03:11:22Z")

</div>

I’ll look into this a bit tomorrow. Looks like there should be some low hanging fruit.

---

<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 25, 2022, 9:59am UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949/67 "2022-01-25T09:59:57Z")

</div>

so, based on the discussion here, I added an example calculation after the `module` in my package main file. It precompiles fine, but then segfaults with something about deserialization when I try to use it. Am I doing something wrong or is this a julia bug that I should report (this is on both 1.7 and nightly)? I’m not using ` __precompile__ (true)` as the docstring says it’s the default?

[Previous page](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949.md?page=2)

[Next page](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949.md?page=4)
