# Weird interaction between packages

**URL:** <https://discourse.julialang.org/t/weird-interaction-between-packages/106306>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 16, 2023, 10:12am UTC](https://discourse.julialang.org/t/weird-interaction-between-packages/106306 "2023-11-16T10:12:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [November 16, 2023, 10:12am UTC](https://discourse.julialang.org/t/weird-interaction-between-packages/106306/1 "2023-11-16T10:12:00Z")

</div>

I am trying to reduce the load time of my project. What I found, using:

```julia
using Timers; tic()

using MAT, PyPlot

function read_lookup(varname="Tables")
    file = matopen(joinpath("data", "TablesCpCtCq.mat"))
    res = read(file, varname)
    close(file)
    res
end

start=toc()
tables=read_lookup()
stop=toc()
println(stop-start)

# Startup: 0.8s
# read_lookup: 1.2s

# without PyPlot
# Startup: 0.0s
# read_lookup: 0.4s

```

I am just looking at the initial compilation time and I am using a custom system image.

If I do not load PyPlot, the first call to read\_lookup needs 0.4s, if I have `using PyPlot` in the code the same call needs 1.2s.

Any idea?

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [November 16, 2023, 10:23am UTC](https://discourse.julialang.org/t/weird-interaction-between-packages/106306/2 "2023-11-16T10:23:52Z")

</div>

It’s probably method invalidation:

> **[Analyzing sources of compiler latency in Julia: method invalidations](https://julialang.org/blog/2020/08/invalidations/#method_invalidation_what_is_it_and_when_does_it_happen)**
>
> 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.

See the following if you want to analyze further:  
[https://timholy.github.io/SnoopCompile.jl/dev/snoopr/](https://timholy.github.io/SnoopCompile.jl/dev/snoopr/)

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [November 16, 2023, 10:25am UTC](https://discourse.julialang.org/t/weird-interaction-between-packages/106306/3 "2023-11-16T10:25:01Z")

</div>

Better example, includes a function to create the test file:

```julia
using Timers; tic()

using MAT#, PyPlot

function read_lookup(varname="varname")
    file = matopen("matfile.mat")
    res = read(file, varname)
    close(file)
    res
end

function create_mat_file()
    variable=zeros(40,40)
    file = matopen("matfile.mat", "w")
    write(file, "varname", variable)
    close(file)
end

start=toc()
tables=read_lookup()
stop=toc()
println(stop-start)

# Startup: 0.83s
# load_mat: 0.73s

# without PyPlot
# Startup: 0.0s
# load_mat: 0.4s

```
