Term.jl
Term.jl copied to clipboard
precompile
@VarLad I've opened this to discuss https://github.com/FedeClaudi/Term.jl/issues/141
This is a branch from master
while before I was testing the development branch for the up-coming version, I thought this might make things easier.
BEFORE using snoopcompile
AFTER
Codecov Report
Merging #147 (1c9eda7) into master (1a28d2c) will decrease coverage by
0.04%
. The diff coverage isn/a
.
@@ Coverage Diff @@
## master #147 +/- ##
==========================================
- Coverage 92.15% 92.10% -0.05%
==========================================
Files 34 34
Lines 2102 2102
==========================================
- Hits 1937 1936 -1
- Misses 165 166 +1
Impacted Files | Coverage Δ | |
---|---|---|
src/Term.jl | 90.00% <ø> (ø) |
|
src/markdown.jl | 90.62% <0.00%> (-1.05%) |
:arrow_down: |
:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more
@FedeClaudi For me, without the PR
julia> @time using Term
0.154946 seconds (376.62 k allocations: 26.304 MiB, 19.63% gc time, 0.88% compilation time)
julia> @time Panel()
0.192432 seconds (1.51 M allocations: 81.944 MiB, 5.80% gc time, 99.76% compilation time)
With the PR
julia> @time using Term
0.308751 seconds (828.32 k allocations: 56.760 MiB, 10.23% gc time, 0.73% compilation time)
julia> @time Panel()
0.056048 seconds (4.30 k allocations: 176.258 KiB, 99.35% compilation time)
Which is appropriate (it increases the precompile time, doubles the load time, but reduces the execution time)
@FedeClaudi Also, in your "AFTER", notice that you're including the Precompile time with the compile time.
I'd recommend to close the Julia session after your first using Term
and then do
@time using Term
@time Panel("test")
again
I see what you mean, the first time using Term
is called its a bit slower but after that it loads faster for future sessions, neat.
Which is appropriate (it increases the precompile time, doubles the load time, but reduces the execution time)
I guess what I'm confused about is that despite precompilation @time Panel()
shows that some compilation is still done:
julia> @time using Term
0.391873 seconds (815.66 k allocations: 54.100 MiB, 2.91% compilation time: 85% of which was recompilation)
julia> @time Panel()
0.081357 seconds (6.94 k allocations: 322.232 KiB, 99.33% compilation time)
╭──────────────────────────────────────────────────────────────────────────────────────╮
╰──────────────────────────────────────────────────────────────────────────────────────╯
julia> @time Panel()
0.000223 seconds (338 allocations: 22.773 KiB)
╭──────────────────────────────────────────────────────────────────────────────────────╮
╰──────────────────────────────────────────────────────────────────────────────────────╯
Not that it makes a huge difference, but I would've thought that the first @time Panel()
would be the same as the second since Panel()
should be pre-compiled?
@FedeClaudi
Not that it makes a huge difference, but I would've thought that the first @time Panel() would be the same as the second since Panel() should be pre-compiled?
We can't precompile everything :P Also, I tried direct precompilation (without the SnoopPrecompile lines)
if ccall(:jl_generating_output, Cint, ()) == 1 # if we're precompiling the package
let
Panel()
Panel("test") * Panel(Panel()) / hLine(20) |> tprint
Panel(Panel("Text"))
end
end
just before the module ends. The results are similar-ish.
Whats concerning though is, I see that there is a lot of cache invalidation, which triggers recompilation. (for example with Panel("Some text")
). You can see that in your own results in the above comments.
I believe this can be avoided with changes in the package itself, and lowering the invalidation where possible will make the entire package more usable.
https://timholy.github.io/SnoopCompile.jl/dev/snoopr/#invalidations
I think this is going to take more time and effort, but it certainly looks doable. I'd recommend to keep the draft open for now. I'll look into whats specifically causing the invalidations with more time. :D
Thanks a lot for taking the time to look into this though
Thank you! Precompilation and TTX is one of the areas of Julia I haven't digged into yet. Input from Term's users that want to improve the package is always the best motivation to get me to do things!
I'll look into whats specifically causing the invalidations with more time. :D
That would be great! I will also look into stuff, but I first need to learn a bit more about pre-compilation,methods invalidation etc... any help would be great.
P.s.: term is not very type stable at all, would that make pre-compilation less effective?
P.s.: term is not very type stable at all, would that make pre-compilation less effective?
I think that would contribute to the problems, yes. I'd recommend into looking into https://timholy.github.io/SnoopCompile.jl/dev/ . The docs have a lot of good points and have a few tools to help you make your package faster. :D
As fully optimizing TTX will be a more involved project, I will merge this for now and leave the issue open as a reminder for when I will have the time. This will already help a little bit, I will release a new version today/tomorrow with this precompilation bit if you want to get it.