MichaelHatherly / CommonMark.jl

A CommonMark-compliant Markdown parser for Julia.
Other
84 stars 11 forks source link

add `SnoopPrecompile` and `precompile.jl` #59

Closed tfiers closed 1 year ago

tfiers commented 1 year ago

Re https://timholy.github.io/SnoopCompile.jl/stable/#Who-should-use-this-package and the "time to first task" efforts in the Julia community.

Comparing startup times on my modern Windows laptop, Julia 1.8.1:

Precompile time: ±7sec

Usage times:

@time using CommonMark
Before: 0.19 seconds (175 k allocations: 43.9 MiB, 8.15% compilation time)
After:  0.71 seconds (586 k allocations: 67.3 MiB, 2.34% compilation time)

@time parser = Parser()
Before: 1.80 seconds (2.36 M allocations: 121.9 MiB, 7.93% gc time, 99.94% compilation time)
After:  0.85 seconds (21 k allocations: 1.0 MiB, 99.93% compilation time)

@time ast = parser("Hello *world*")
Before: 1.45 seconds (1.74 M allocations: 88.1 MiB, 7.20% gc time, 99.98% compilation time)
After:  1.07 seconds (24 k allocations: 1.2 MiB, 99.98% compilation time)

@time CommonMark.html(ast)
Before: 0.26 seconds (276.43 k allocations: 14.2 MiB, 99.91% compilation time)
After:  0.25 seconds (5 k allocations: 250.3 KiB, 99.91% compilation time)

Total:
Before: 3.70 seconds
After:  2.88 seconds

So a modest improvement, but an improvement nonetheless. And with the upcoming native code caching, this hopefully increases further in the following Julia releases.

tfiers commented 1 year ago

Just read that the plan is to integrate in stdlib, so a new non-stdlib dependency might not be appropriate. Let me know @mortenpi if I should close this.

EDIT I should maybe replace the current @precompile_all_calls block with manual precompile calls. Then there is no new dep needed.

EDIT2 Oops wrong tag, that should've been @ MichaelHatherly. Sorry Morten!

tfiers commented 1 year ago

Voila, looking forward to your comments.

(Shortcut link to benchmark result of latest commit: https://github.com/tfiers/CommonMark.jl/blob/master/benchmark/results/startup-time.md)

tfiers commented 1 year ago

It might be an idea to run the new benchmark/make.jl in CI (github actions). To track possible future regressions in speed.

MichaelHatherly commented 1 year ago

It might be an idea to run the new benchmark/make.jl in CI (github actions). To track possible future regressions in speed.

Can be done in a follow up PR if you want, no need for it to be in this one as well.

MichaelHatherly commented 1 year ago

@tfiers anything else you'd like to add to this PR, or is it good to go from your end?

tfiers commented 1 year ago

GTM, thanks for looking into it

MichaelHatherly commented 1 year ago

:laughing: I should have included this in 0.8.8... oh well, 0.8.9 coming soon I guess.

MichaelHatherly commented 1 year ago

Will be included in https://github.com/JuliaRegistries/General/pull/75901.