# Specifying which lines I want to be fast

**URL:** <https://discourse.julialang.org/t/specifying-which-lines-i-want-to-be-fast/60699>\
**Category:** Performance\
**Created:** [May 7, 2021, 8:12am UTC](https://discourse.julialang.org/t/specifying-which-lines-i-want-to-be-fast/60699 "2021-05-07T08:12:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [May 7, 2021, 8:12am UTC](https://discourse.julialang.org/t/specifying-which-lines-i-want-to-be-fast/60699/1 "2021-05-07T08:12:52Z")

</div>

I want most of my code to be interpreter-slow in order to avoid compiler latency, but one or two lines need to be compiled-fast. Is it possible to get both of those in the same session?

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [May 7, 2021, 1:06pm UTC](https://discourse.julialang.org/t/specifying-which-lines-i-want-to-be-fast/60699/2 "2021-05-07T13:06:40Z")

</div>

You can use the (experimental) `Base.Experimental.@optlevel` to set the optimization level for a given module, e.g.:

```julia
module SlowCode

@Base.Experimental.optlevel 0

<slow code here>

end

module FastCode

@Base.Experimental.optlevel 2 # this is the default

<fast code here>

end

```

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [May 7, 2021, 1:10pm UTC](https://discourse.julialang.org/t/specifying-which-lines-i-want-to-be-fast/60699/3 "2021-05-07T13:10:31Z")

</div>

There’s no “line based” interpreter switch - functions are compiled wholesale. Julia is compiled by default, though there is [JuliaInterpreter](https://github.com/JuliaDebug/JuliaInterpreter.jl) which is mostly used in debugging.

May I ask which code is sensitive to compile latency/your usecase for this?

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [May 7, 2021, 6:45pm UTC](https://discourse.julialang.org/t/specifying-which-lines-i-want-to-be-fast/60699/4 "2021-05-07T18:45:31Z")

</div>

> [@Sukera](#):
>
> May I ask which code is sensitive to compile latency/your usecase for this?

When I start a session it takes a minute or two to get going, which reduces productivity in exchange for performance I _mostly_ don’t need. It’s the time-to-first-result issue but with a twist. For example, I do a bunch of imports (slow is fine), some data manipulation (slow is fine), run an estimator (needs to be fast or it’ll take all day), plot the result (slow is fine).

Ideally the compiler could look at my program and figure out how to minimize the time-to-result by trading off compilation time against run time.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [May 7, 2021, 6:55pm UTC](https://discourse.julialang.org/t/specifying-which-lines-i-want-to-be-fast/60699/5 "2021-05-07T18:55:26Z")

</div>

You may want to look into [Revise.jl](https://juliahub.com/ui/Packages/Revise/M1Qoh/3.1.15) (smart reloading of code) or [Pluto.jl](https://juliahub.com/ui/Packages/Pluto/OJqMt/0.14.5) (reactive notebooks).
