# Compiler work priorities

**URL:** <https://discourse.julialang.org/t/compiler-work-priorities/17623>\
**Category:** Internals & Design\
**Created:** [November 16, 2018, 10:14pm UTC](https://discourse.julialang.org/t/compiler-work-priorities/17623 "2018-11-16T22:14:46Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [December 30, 2018, 8:55pm UTC](https://discourse.julialang.org/t/compiler-work-priorities/17623/61 "2018-12-30T20:55:34Z")

</div>

IMHO the compilation time can be annoying sometimes, but nothing you can’t get used to (I worked with MATLAB + CMEX that crashes MATLAB more often that I want, given my coding skils, making me waiting the 40s startup time…). However, by comparing the workflow I had with MATLAB, I really miss a debugger. Very complex algorithms like [this](https://github.com/JuliaSpace/SatelliteToolbox.jl/blob/master/src/orbit/propagators/sgp4.jl) would have been implemented and tested way faster if Julia had even a primitive kind of debugger.

---

<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:** [December 30, 2018, 9:08pm UTC](https://discourse.julialang.org/t/compiler-work-priorities/17623/62 "2018-12-30T21:08:13Z")

</div>

A few common reasons:

1. I often change struct definitions.
2. I modify functions while making them more general in the types they accept. Then the dispatcher still favors the old, when I want to use the new.
3. Modifying packages with lots of generated functions or `@eval` function definitions. I know you made some strong points against generated functions earlier, so maybe this is me being lazy – it’s often easier to write a generated function than to bet on the compiler optimizing some cruft away (which it normally does well). Elegant solutions take more creativity.
4. General concern that things slipped through cracks, so that even if everything is working now, something will be broken when I restart. Hence, why I restart to (hopefully) confirm that this isn’t the case.
5. Lack of awareness of Revise’s latest capabilities.

Some of these would also be resolved if I just wrote unit tests. Which I really should do.

---

<div class="post-metadata">

**Author:** ![tobias.knopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobias.knopp/32/7551_2.png) [@tobias.knopp](https://discourse.julialang.org/u/tobias.knopp)\
**Post date:** [December 30, 2018, 9:11pm UTC](https://discourse.julialang.org/t/compiler-work-priorities/17623/63 "2018-12-30T21:11:10Z")

</div>

Revise has helped me a lot when developing a larger Gtk application which requires roughly 2-3 minutes to precompile and start.

- regarding Revise I have the feeling that Julia (or the REPL) gets pretty slow when Revise is active.

- while Revise is nice for me during development is is really annoying that the users of my Gtk application need to wait for 20 seconds when they hit a button the first time. If there would be a way to “freeze” the current state and ship that to my users that would be awesome.

---

<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:** [December 30, 2018, 10:57pm UTC](https://discourse.julialang.org/t/compiler-work-priorities/17623/64 "2018-12-30T22:57:49Z")

</div>

Restarts: Segfaults, interrupting long running processes that don’t exit gracefully, and type redefinitions.

I’ve developed a type-heavy coding style for model formulation modularity. It seems like the logical conclusion to having multiple dispatch. But it means Revise doesn’t give me whole day sessions because altering types happens all the time.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 30, 2018, 11:44pm UTC](https://discourse.julialang.org/t/compiler-work-priorities/17623/65 "2018-12-30T23:44:13Z")

</div>

> [@tobias.knopp](#):
>
> If there would be a way to “freeze” the current state and ship that to my users that would be awesome.

That’s pretty much what Julia does itself for the REPL and Pkg to be fast (running code while the sysimg is being created). PackageCompiler.jl aims to do the same for user code.

---

<div class="post-metadata">

**Author:** ![tobias.knopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobias.knopp/32/7551_2.png) [@tobias.knopp](https://discourse.julialang.org/u/tobias.knopp)\
**Post date:** [December 30, 2018, 11:51pm UTC](https://discourse.julialang.org/t/compiler-work-priorities/17623/66 "2018-12-30T23:51:00Z")

</div>

> [@kristoffer.carlsson](#):
>
> That’s pretty much what Julia does itself for the REPL and Pkg to be fast (running code while the sysimg is being created). PackageCompiler.jl aims to do the same for user code.

I know but I have not got PackageCompiler working. Making PackageCompiler working reliable and integrating it into base Julia would IMHO be a very good path forward. What I am imagining is a `Pkg` command where you can “add” a package to a global cache file, which is then always compiled if `Pkg` manager recognizes that it needs to.

---

<div class="post-metadata">

**Author:** ![Maurizio\_Tomasi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maurizio_tomasi/32/384_2.png) [@Maurizio\_Tomasi](https://discourse.julialang.org/u/Maurizio_Tomasi)\
**Post date:** [December 31, 2018, 6:23am UTC](https://discourse.julialang.org/t/compiler-work-priorities/17623/67 "2018-12-31T06:23:27Z")

</div>

I completely missed Revise.jl and installed it just today. It’s been a few hours since I am using it, but I am already in love! Thank you so much for this gem!

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [December 31, 2018, 7:15am UTC](https://discourse.julialang.org/t/compiler-work-priorities/17623/68 "2018-12-31T07:15:47Z")

</div>

> [@tim.holy](#):
>
> But part of what I’m interested in is “why do people restart their sessions?” That is, not bugs _per se_ in Revise, but perhaps limitations that force people to restart.

My primary reason is due to struct changes. That happens quite often when building something new and the structs are still evolving. I initially worked around it by using a Dict or named tuple instead of a struct but that doesn’t work too well and eventually I will have to do it right.

Other than that, Revise is the greatest thing that I’ve ever used in any programming environment! Thanks, Tim, for your excellent contribution!

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [December 31, 2018, 10:01am UTC](https://discourse.julialang.org/t/compiler-work-priorities/17623/69 "2018-12-31T10:01:28Z")

</div>

I also keep my session opened for like a week, but when I restart I often find bugs since I have all kind of stuff defined in the global scope.

For struct change I just rename them (search/replace), MyStruct → MyStruct2. Once you are at version 8 and your design is final you can rename to MyStruct and restart.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [December 31, 2018, 3:33pm UTC](https://discourse.julialang.org/t/compiler-work-priorities/17623/70 "2018-12-31T15:33:56Z")

</div>

One thing that’s hinted at in this conversation but which should perhaps be stated explicitly is this: many compilation issues for Julia are not just a matter of implementing standard, well-known solutions—in a lot of ways we’re in a brave new world and finding solutions to compilation issues, given the ways that Julia works, is to a significant extent a series of research projects. A lot of it has to do with inventing and discovering usage patterns that work well and how compilation technologies fit into that. The new way that code loading and environments work seems to be pushing us towards the project environment as a compilation unit, but keep in mind that all of that stuff was brand new as of Julia 1.0, so we’re still learning and adapting.

---

<div class="post-metadata">

**Author:** ![mlhetland](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mlhetland/32/283_2.png) [@mlhetland](https://discourse.julialang.org/u/mlhetland)\
**Post date:** [December 31, 2018, 3:59pm UTC](https://discourse.julialang.org/t/compiler-work-priorities/17623/71 "2018-12-31T15:59:26Z")

</div>

One thing to maybe think about is that it might be possible to improve the latency-related user experience without actually speeding up the compiler – if a program can start doing stuff before its heavier imported modules are compiled (as long as it’s not yet using them, of course). That’s currently my use-case, FWIW (text-based interactive thing that uses JuMP – but only after the first user input).

I guess one could do stuff like that already, but some canonical mechanism, or even just some targeted documentation, might be helpful.

---

<div class="post-metadata">

**Author:** ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)\
**Post date:** [December 31, 2018, 4:57pm UTC](https://discourse.julialang.org/t/compiler-work-priorities/17623/72 "2018-12-31T16:57:46Z")

</div>

In that line of thinking, I hope we see some work done to allow compilation to be done asynchronously in another `Task`, so that already-compiled (or interpreted) code can run in parallel.

I may give this a try once PARTR is merged and libuv is properly thread-safe.

---

<div class="post-metadata">

**Author:** ![Tero\_Frondelius](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tero_frondelius/32/7629_2.png) [@Tero\_Frondelius](https://discourse.julialang.org/u/Tero_Frondelius)\
**Post date:** [December 31, 2018, 5:31pm UTC](https://discourse.julialang.org/t/compiler-work-priorities/17623/73 "2018-12-31T17:31:04Z")

</div>

> [@Ronis\_BR](#):
>
> Very complex algorithms like [this](https://github.com/JuliaSpace/SatelliteToolbox.jl/blob/master/src/orbit/propagators/sgp4.jl) would have been implemented and tested way faster if Julia had even a primitive kind of debugger.

You should consider different coding style with small functions and unit testing. For example all the derivatives should have their own functions which could be tested separately. At least in our development coding the derivatives are easy place to make mistakes. Check Chris Rackauckas YouTube video for an idea of the way of working.

---

<div class="post-metadata">

**Author:** ![tobias.knopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobias.knopp/32/7551_2.png) [@tobias.knopp](https://discourse.julialang.org/u/tobias.knopp)\
**Post date:** [January 1, 2019, 7:36pm UTC](https://discourse.julialang.org/t/compiler-work-priorities/17623/74 "2019-01-01T19:36:59Z")

</div>

> [@StefanKarpinski](#):
>
> One thing that’s hinted at in this conversation but which should perhaps be stated explicitly is this: many compilation issues for Julia are not just a matter of implementing standard, well-known solutions—in a lot of ways we’re in a brave new world and finding solutions to compilation issues, given the ways that Julia works, is to a significant extent a series of research projects.

That is an interesting comment. I think it is totally clear that the solution is lots of work and requires a very high technical understanding. But is there (from a CS point of view) really a research question in there? Or hasn’t e.g. Java basically developed solutions for minimization of latency in a JIT world? Don’t read that as a comment to adopt solutions from the Java world, I am just curious how much research is in there.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [January 2, 2019, 12:26pm UTC](https://discourse.julialang.org/t/compiler-work-priorities/17623/75 "2019-01-02T12:26:09Z")

</div>

Some of it applies. We should probably work towards a tiered JIT system where code first executes in a slow but fast-to-generate form and upgrades to faster versions when available.

Many languages, including Java, have been designed with support for separate compilation of modules as a hard design requirement. We explicitly disregarded that when designing Julia because it seemed like too much of a stifling limitation. But that makes it hard to figure how to generate catchable units of compiled code. C++ code with heavy use of templates has a similar issue not coincidentally—it has many of the same benefits as Julia for similar reasons. The main difference is that C++ compile time is earlier. Figuring out this bit is one of the big challenges.

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [January 2, 2019, 12:38pm UTC](https://discourse.julialang.org/t/compiler-work-priorities/17623/76 "2019-01-02T12:38:16Z")

</div>

I’m extremely interested in the potential solutions to the latency issue, and I find all these informed opinions really valuable. So @StefanKarpinski, from your vantage viewpoint on the compiler internals, how hard to implement do you think this tiered JIT functionality might turn out to be? Are we talking about a major 3.0 redesign thing, or is the current compiler design extensible enough to integrate such functionality seamlessly (given enough man hours)?

---

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [January 2, 2019, 1:04pm UTC](https://discourse.julialang.org/t/compiler-work-priorities/17623/77 "2019-01-02T13:04:15Z")

</div>

> [@StefanKarpinski](#):
>
> We explicitly disregarded that when designing Julia because it seemed like too much of a stifling limitation.

Can you give some hints where this limitation is realized?

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [January 2, 2019, 2:26pm UTC](https://discourse.julialang.org/t/compiler-work-priorities/17623/78 "2019-01-02T14:26:41Z")

</div>

Composing generic code with specific types and generating fully optimized machine code.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [January 2, 2019, 2:27pm UTC](https://discourse.julialang.org/t/compiler-work-priorities/17623/79 "2019-01-02T14:27:00Z")

</div>

Should be possible but it’s a fair amount of work.

---

<div class="post-metadata">

**Author:** ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)\
**Post date:** [January 2, 2019, 4:26pm UTC](https://discourse.julialang.org/t/compiler-work-priorities/17623/80 "2019-01-02T16:26:04Z")

</div>

I imagine it wouldn’t be breaking or necessarily 3.0-worthy (but probably on the 2.0 timeline) since we can already run julia in fully-interpreted mode with `compile=no`. From my perspective, we “just” need to implement the heuristics and mechanisms for switching between interpreting and different optimization levels, and then remove all the various assumptions that may be hard-coded in that assume that the optimization level can’t change during runtime.

[Previous page](https://discourse.julialang.org/t/compiler-work-priorities/17623.md?page=3)

[Next page](https://discourse.julialang.org/t/compiler-work-priorities/17623.md?page=5)
