-
-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generated executable is slow (doing JIT?) #292
Comments
Unfortunately, my guess that this problem is restricted to Windows is not correct. I have now run the MWE on MacOS and on Linux, with the same result: The generated executable is slow, consistent with it carrying out JIT compilation every time it's run.
|
Please try again with the new API. If it still doesn't work, it would be useful to get a reproduces so I can figure out what is happening. |
I've got a very simple reproducer (I think) on the current master:
module Foo
fib(n::Int) = n < 2 ? n : fib(n-1) + fib(n-2)
function julia_main()::Cint
n = isempty(ARGS) ? 30 : parse(Int, ARGS[1])
@time @show fib(n)
@time @show fib(n)
return 0
end
end # module
using Foo
Foo.fib(10)
Foo.fib(20)
Foo.fib(30)
Foo.julia_main()
using PackageCompiler
create_app(".", "build", precompile_execution_file="precompile.jl", force=true)
Notice that the first invocation of Masons-MacBook-Pro:Foo mason$ julia --project=. --startup=no -q
julia> using Foo; Foo.julia_main()
[ Info: Precompiling Foo [c0d64c21-6ac2-435c-84ed-380d3bba6884]
fib(n) = 832040
0.018421 seconds (25.66 k allocations: 1.218 MiB)
fib(n) = 832040
0.004355 seconds (14 allocations: 736 bytes)
0 Am I doing something wrong in the |
Here's my version info: julia> versioninfo()
Julia Version 1.4.0-rc1.0
Commit b0c33b0cf5 (2020-01-23 17:23 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin19.2.0)
CPU: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-8.0.1 (ORCJIT, skylake)
Environment:
JULIA_NUM_THREADS = 2 |
I don't really think that is the same issue. The issue in OP was about something taking 8 seconds the first time and then being instant. Here we are talking about something that takes 0.02 seconds the first time. I think the reason for the short first delay is that when we precompile stuff,
When we then run the executable, we do output to a TTY so what actually ends up getting compiled is:
|
If I change the PackageCompiler.jl/src/PackageCompiler.jl Line 170 in 68530ef
I get the correct
That would print all the output from the precompiling though. I could also use the same was a Base does by creating a fake TTY (https://github.com/JuliaLang/julia/blob/0fe45ef7349b6ad25fdba7dce169f9b9efa48620/contrib/generate_precompile.jl#L82) and use that. Or I could just try to compile all methods for |
I just tried that and indeed it's fast! Thanks for the pointers and investigation. Personally, I don't see a huge problem with printing the precompile statements, but maybe there's a way to filter them out? |
The OP said:
So I suspected that it was something similar where there was a precompile statement that wasn't doing what the OP intended it to do. In this case, I thought it might have to do with the machinery to parse the array, but I'm out of my depth. |
Yeah, I understand it is easy to think they are related but your case is more of a small inaccuracy while the case in OP seems to be a complete absence of precompilation.
Well, the tricky part is that e.g. using
My guess is that this is the OS running some scan (security?) or something the first time it is loaded. There should not be any precompilation. |
If we use Maybe I should open a PR with that |
I've done that and I'm happy to report that the new API works correctly against my MWE (mutated as necessary). So I've closed this issue (since I see that @MasonProtter has opened a separate one). |
Thanks for the update! |
This is a cross-post from StackOverflow.
Though I can get
build_executable
to generate an exe file, that exe's performance is poor, consistent with it carrying out a JIT compilation every time it's called, despite my having used a snoop file designed to avoid that. This may be a bug (perhaps restricted to Windows?) or I may be failing correctly to use the functionality provided by PackageCompiler.Here is my MWE:
TestBuildExecutable.jl
contains:SnoopFile.jl
contains:In a fresh Julia instance,
julia_main
takes 8.3 seconds for the first execution and half a millisecond for the second execution:Call
build_executable
:Finally, in a Windows Command Prompt:
which took (by my stopwatch) 8 seconds to run, and it takes 8 seconds to run every time it's executed, not just the first time. This is consistent with the executable doing a JIT compile every time it's run, but the snoop file is designed to avoid that!
Version information:
The text was updated successfully, but these errors were encountered: