Skip to content

Instantly share code, notes, and snippets.

@KristofferC
Created July 12, 2018 12:22
Show Gist options
  • Save KristofferC/fa50a2b32d1f684f9ed35d23143166c3 to your computer and use it in GitHub Desktop.
Save KristofferC/fa50a2b32d1f684f9ed35d23143166c3 to your computer and use it in GitHub Desktop.
options_path = "src/options.h"
if !isfile(options_path)
error("current working dir must be the julia directory")
end
println("Welcome to the custom precompile statement builder")
sleep(1)
println("First we will rebuild julia to emit what functions it compile")
sleep(1)
options = read(options_path, String)
write(options_path, replace(options, "//#define TRACE_COMPILE" => "#define TRACE_COMPILE"))
run(`make -j4`)
println("Now we will record all functions used by julia when it starts up")
sleep(1)
println("Feel free to play around a bit in the REPL as well, exit the started julia when done")
run(pipeline(`./julia`; stderr="precompile.txt"))
println("Precompile statements written, recompiling julia with the new statements!")
sleep(1)
precompiles = readlines("base/precompile.jl")
new_precompiles = String[]
for p in readlines("precompile.txt")
if startswith(p, "precompile")
push!(new_precompiles, p)
end
end
# Two last lines in precompile.jl are end of modules.
# Insert before those
i = length(precompiles) - 3
precompiles_after = [precompiles[1:i]; new_precompiles; precompiles[i+1:end]]
write("base/precompile.jl", join(precompiles_after, '\n'))
write(options_path, replace(options, "#define TRACE_COMPILE" => "//#define TRACE_COMPILE"))
run(`make -j4`)
println("Please restart julia and enjoy a snappier REPL")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment