From bcddb6cb064484e081b6feb035a0ae491bec863b Mon Sep 17 00:00:00 2001 From: Hugo Levy-Falk Date: Sat, 20 Jul 2024 22:35:10 +0200 Subject: [PATCH] feat(script): Add PrecompileTools.jl pass to make the script more user friendly. Before change: ```bash $ time runic --help ... julia -e 'using Runic; exit(Runic.main(ARGS))' -- --help 5.14s user 0.15s system 101% cpu 5.215 total ``` After: ```bash $ time runic --help ... julia -e 'using Runic; exit(Runic.main(ARGS))' -- --help 0.24s user 0.15s system 129% cpu 0.301 total ``` --- Project.toml | 2 ++ src/Runic.jl | 1 + src/precompiletools.jl | 51 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 src/precompiletools.jl diff --git a/Project.toml b/Project.toml index e11328f..603472a 100644 --- a/Project.toml +++ b/Project.toml @@ -4,9 +4,11 @@ version = "1.0.0" [deps] JuliaSyntax = "70703baa-626e-46a2-a12c-08ffd08c73b4" +PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" [compat] JuliaSyntax = "0.4.8" +PrecompileTools = "1" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/src/Runic.jl b/src/Runic.jl index a371a46..0fc02f5 100644 --- a/src/Runic.jl +++ b/src/Runic.jl @@ -412,5 +412,6 @@ end include("runestone.jl") include("main.jl") +include("precompiletools.jl") end # module diff --git a/src/precompiletools.jl b/src/precompiletools.jl new file mode 100644 index 0000000..4bbec25 --- /dev/null +++ b/src/precompiletools.jl @@ -0,0 +1,51 @@ +using PrecompileTools: @setup_workload, @compile_workload +@setup_workload begin + bad_bad_code = """# Some ill-formatted julia code to fire-up Runic.jl! + # This is simply taken from runstone + print( "chaotic use of spaces (yes there's one space at the end of the line") + + \tprint( "chaotic use of tabs")\t + a = 0x1 + b= 1. + c=1.00 + d=0+2 + + + e=( + 1,2,3, + 4) + ( e...,) + a==3 ? println( "foo") : nothing + struct bar <: Int + end + for i=1:1_000 + nothing + end + function hello(::T) where T<:Int + println("No") + println("Indentation") + println("shall") + println("stop me.") + end + a + + b + 3+1:9*5 + + """ + filepath, io = mktemp() + write(io, bad_bad_code) + close(io) + @compile_workload begin + redirect_stdio(stdout = devnull, stderr = devnull) do + # Format this bad bad code + main(["-v", "-o", tempname(), filepath]) + # Help print + main(["--help"]) + # If git is available + git = Sys.which("git") + if !isnothing(git) + main(["--diff", "--check", filepath]) + end + end + end +end