dhoegh / BuildExecutable.jl

Build a standalone executables from a Julia script
Other
156 stars 21 forks source link

Executable takes a very long time to start up #28

Closed pron closed 7 years ago

pron commented 7 years ago

Hi. I've used build_executable to compile a very simple program:

function main()
    for x in ARGS
        println("Hi: $x")
    end
end

The produced executable takes over 6 seconds to run!

What is happening in those 6 seconds? Is it compilation? Is there a way to precompile everything I need?

blegat commented 7 years ago

This is a follow up from this reddit post

ihnorton commented 7 years ago

The issue is that the output of BuildExecutable does not actually load the associated precompiled image, so everything must be JIT'd again before the app can do anything. You can get normal (faster) startup by specifying the image manually:

JULIA_SYSIMAGE=libapp.dylib ./app Hello

(from the build directory, using the build command from your reddit post)

pron commented 7 years ago

It works! Thank you very much. You may want to consider adding it to the README. Could this be automatically done by the executable?

P.S.

I'm very new to Julia. Where is the best place to ask questions? Reddit? SO? discourse.julialang.org?

MatthiasErdmann commented 7 years ago

Hi, I am also very new to Julia (have been using Matlab/Python for many years). I am using Julia 0.5.0 64bit on Windows and have tried to compile a simple program using build_executable, but I have not been successful - the process always breaks with a Load Error:

ERROR: LoadError: failed process: Process('C:\Users\merdmann\.julia\v0.5\WinRPM\deps\usr\x86_64-w64-mingw32\sys-root\mingw\bin\gcc.exe' '-LC:\Julia-0.5.0\bin' -shared -ljulia -lssp -o 'C:\Julia-0.5.0\bin\libapp.dll' 'C:\Julia-0.5.0\bin\libapp.o', ProcessExited(1)) [1] in pipeline_error(::Base.Process) at .\process.jl:616 in run at .\process.jl:592 [inlined] in link_sysimg(::String, ::String, ::Bool) at C:\Users\merdmann.julia\v0.5\BuildExecutable\src\build_sysimg.jl:151 in (::##2#3{Bool,String})() at C:\Users\merdmann.julia\v0.5\BuildExecutable\src\build_sysimg.jl:80 in cd(::##2#3{Bool,String}, ::String) at .\file.jl:48 in #build_sysimg#1(::Bool, ::Bool, ::Function, ::String, ::String, ::String) at C:\Users\merdmann.julia\v0.5\BuildExecutable\src\build_sysimg.jl:38 in (::#kw##build_sysimg)(::Array{Any,1}, ::#build_sysimg, ::String, ::String, ::String) at .\:0 in include_from_node1(::String) at .\loading.jl:488 in process_options(::Base.JLOptions) at .\client.jl:262 in _start() at .\client.jl:318 while loading C:\Users\merdmann.julia\v0.5\BuildExecutable\src\build_sysimg.jl, in expression starting on line 187

Would you mind to help me with this problem? Thanks a lot!

blegat commented 7 years ago

Julia just says that the command has failed and does not give more info. Could you run the command (i.e. C:\Users\merdmann\.julia\v0.5\WinRPM\deps\usr\x86_64-w64-mingw32\sys-root\mingw\bin\gcc.exe' '-LC:\Julia-0.5.0\bin' -shared -ljulia -lssp -o 'C:\Julia-0.5.0\bin\libapp.dll' 'C:\Julia-0.5.0\bin\libapp.o) in a terminal and tell us the output ?

MatthiasErdmann commented 7 years ago

Unfortunately, the command does not produce any output - the command syntax seems to be incorrect.

The final Julia error message is:

LoadError: failed process: Process('C:\Julia-0.5.0\bin\julia' 'C:\Users\merdmann\.julia\v0.5\BuildExecutable\src\build_sysimg.jl' 'C:\Julia-0.5.0\bin\libapp' native 'C:\Users\merdmann\AppData\Local\Temp\jl_D63E.tmp\userimg.jl' --force, ProcessExited(1)) [1] in pipeline_error(::Base.Process) at .\process.jl:616 in run at .\process.jl:592 [inlined] in #build_executable#1(::Bool, ::Bool, ::Function, ::String, ::String, ::String, ::String) at C:\Users\merdmann.julia\v0.5\BuildExecutable\src\BuildExecutable.jl:116 in build_executable(::String, ::String, ::String, ::String) at C:\Users\merdmann.julia\v0.5\BuildExecutable\src\BuildExecutable.jl:54 in include_string(::String, ::String) at .\loading.jl:441 in include_string(::Module, ::String, ::String) at C:\Users\merdmann.julia\v0.5\CodeTools\src\eval.jl:32 in (::Atom.##61#64{String,String})() at C:\Users\merdmann.julia\v0.5\Atom\src\eval.jl:81 in withpath(::Atom.##61#64{String,String}, ::String) at C:\Users\merdmann.julia\v0.5\CodeTools\src\utils.jl:30 in withpath(::Function, ::String) at C:\Users\merdmann.julia\v0.5\Atom\src\eval.jl:46 in macro expansion at C:\Users\merdmann.julia\v0.5\Atom\src\eval.jl:79 [inlined] in (::Atom.##60#63{String,String})() at .\task.jl:60 while loading C:...\julia_sandbox\compilejulia.jl, in expression starting on line 2

My Julia version is 0.5.0 release x86_64-w64-mingw32 - but why mingw32? Does this point to a 64bit/32bit conflict?

blegat commented 7 years ago

What I meant is executing the gcc command outside julia. If this commands has now output it means that it succeeded. Did you run

gcc.exe '-LC:\Julia-0.5.0\bin' -shared -ljulia -lssp -o 'C:\Julia-0.5.0\bin\libapp.dll' 'C:\Julia-0.5.0\bin\libapp.o

?

MatthiasErdmann commented 7 years ago

Ok - indeed, when leaving out all single quotation marks (but only then), gcc.exe -LC:\Julia-0.5.0\bin -shared -ljulia -lssp -o C:\Julia-0.5.0\bin\libapp.dll C:\Julia-0.5.0\bin\libapp.o does succeed (has no output).

blegat commented 7 years ago

Good catch ! Let's see what @dhoegh thinks about it. Could you use the "Insert code" button to format the codes in your posts ? it makes it a lot more readable ;)

MatthiasErdmann commented 7 years ago

Ok, By the way, I just tried compiling under Linux (Ubuntu 16.04) and got a similar error.

dhoegh commented 7 years ago

@MatthiasErdmann I have looked into the issue you are having and it is not related to this issue. The main issue you are having is probably related to the issue I am displaying below. If I am trying to run the command manually in CMD on windows I get the following error: image @MatthiasErdmann I suspect that when you execute the command manually you use a globally installed GCC while BuildExecutable uses a local one, installed by WinRPM in something like C:\Users\d-hoe\.julia\v0.5\WinRPM\deps\usr\x86_64-w64-mingw32\sys-root\mingw\bin\gcc.exe.

Do any one have an idea what is causing the build to fail with missing libwinpthread-1.dll? I suspect it is caused by an newer GCC. Appveyor has just begun failing, while a month old build succeeded.

dhoegh commented 7 years ago

From http://download.opensuse.org/repositories/windows:/mingw:/win64/openSUSE_Factory/x86_64/ it seems the GCC version was updated 2016-12-30.

MatthiasErdmann commented 7 years ago

Actually, I have used the local gcc installed by WinRPM - Pkg.add("BuildExecutable") leads to the installation of gcc version 6.3.0 under C:\Users\"me"\.julia\v0.5\WinRPM\deps\usr\x86_64-w64-mingw32\sys-root\mingw\bin. However, I get no error message concerning libwinpthread-1.dll. I don't know if this might give hint, but during installation of the BuildExecutable package there is an INFO: "Multiple package candidates found for mingw64-unistd-pthread-devel, picking newest".

boonpingng commented 7 years ago

Hi,

@MatthiasErdmann, I have the same problem.

You need to path your "C:\Users\"me".julia\v0.5\WinRPM\deps\usr\x86_64-w64-mingw32\sys-root\mingw\bin" in order to run the libwinpthread-1.dll. But after running, nothing happen.

image

Seem like the system execute the comment but there are no .exe file generated.

pron commented 7 years ago

I'm experiencing the same problem as @MatthiasErdmann on Windows. I'll report more details tomorrow.

dhoegh commented 7 years ago

Good news, I have a fix for the windows issue in #30.

MatthiasErdmann commented 7 years ago

Thank you! Adding the bin dir of the local gcc (C:\Users\"me"\.julia\v0.5\WinRPM\deps\usr\x86_64-w64-mingw32\sys-root\mingw\bin) to $PATH works for me.

boonpingng commented 7 years ago

Thanks dhoegh.

dhoegh commented 7 years ago

I have now changed so BuildExecutable to use precompiled image in #32. Please do a Pkg.checkout("BuildExecutable") and verify it fixes the problem.

pron commented 7 years ago

It works (at least on Mac). Thank you very much for the quick fix!