Coder Social home page Coder Social logo

Comments (14)

fguevaravas avatar fguevaravas commented on May 24, 2024 1

@mauro3, I did see improvements with the userimg.jl method, and I found a much simpler way that doesn't use SnoopCompile.jl. The solution involves putting everything in a module and invoking parse_args once. Here it is:

https://gist.github.com/fguevaravas/cf1478548f8431a7a49002a416e6ca74

What I don't like is that it takes a few minutes to generate a new system image. Less than ideal.

from argparse.jl.

fguevaravas avatar fguevaravas commented on May 24, 2024 1

Although this is only anecdotal evidence, the startup time did slow in my application when I went from Julia v0.5.2 to v0.6.0 and I didn't use any of the compilation methods explained in this thread.

On the bright side, the startup time if you compile with the Static AOT Julia compilation technique is significantly down. This AOT approach doesn't build the system image from scratch, it uses the one from the current Julia installation and adds the compiled version of your code to it. I would give this approach a try instead of the build_sysimg approach if you really want to reduce start up times.

from argparse.jl.

fguevaravas avatar fguevaravas commented on May 24, 2024 1

Hi @non-Jedi here is an example inspired from an earlier version of Static AOT Julia compilation and BuildExecutable.jl:

https://gist.github.com/fguevaravas/a419948d8789da87303e72c7f17b830c

I would recommend you use Static AOT Julia compilation, though. It compiles julia code in a more user friendly and general manner than what I show in the previous example. This juliac will hopefully be bundled with julia later.

from argparse.jl.

carlobaldassi avatar carlobaldassi commented on May 24, 2024

Last time I checked, this was entirely due to 1) julia startup time, in some small part, and mostly 2) compilation of functions within Base julia. The only real solution for that would be compiling julia from source with those functions pre-compiled in userimg.jl. (Or faster compilation times...)

The way I checked that this was the case was by running something like argparse_example.jl from the julia REPL twice, you'll see that the second time is almost instantaneous. The ArgParse functions, and the TextWrap functions that are called, are also already pre-compiled (see this file).

I don't think there is much that can be done here. If you want to check for yourself, or try the usrimg.jl way, I recommend to start from the SnoopCompile README.

from argparse.jl.

fguevaravas avatar fguevaravas commented on May 24, 2024

Ok this is really not an issue with ArgParse. I tried the usrimg.jl way and it reduces load times to a more acceptable 0.5s. Thanks for suggesting it.

I have also tried putting the function main(args) definition (from the same example) inside a module with the __precompile__() and explicitly adding precompile(main,(Array{String,1},)) to the end of the module. I thought this would have the same effect as the speed up one sees by calling a function twice in the REPL (or building the system image) but it doesn't seem to work. Any ideas why this is the case?

from argparse.jl.

carlobaldassi avatar carlobaldassi commented on May 24, 2024

I think it's just that precompilation of a function does not also compile the functions called within it. Calling the function explicitly does though.

from argparse.jl.

fguevaravas avatar fguevaravas commented on May 24, 2024

I consider this closed as it is a Julia precompilation issue. Thanks for your advice.

from argparse.jl.

mauro3 avatar mauro3 commented on May 24, 2024

@fguevaravas: could you post the usrimg.jl you used?

from argparse.jl.

mauro3 avatar mauro3 commented on May 24, 2024

I just saw that @fguevaravas is not very active. @carlobaldassi: do you have a list of the base-functions needed precompilation?

from argparse.jl.

fguevaravas avatar fguevaravas commented on May 24, 2024

I generated a userimg.jl file using the method in SnoopCompile, i.e. you do a sample run of your julia code and this package records all functions that are compiled. Then one can use this info to generate a system image (it takes a long time though) which can speed up load times. I found the procedure extremely complicated for something so basic, so I am just waiting 2-5s every time my CLI program runs.

It would be much better to be able to add the equivalent of userimg.jl to each module. For example if we know we will be using comparisons of strings a lot, then it makes sense to precompile comparisons of strings within the module... AFAIK this doesn't work because the comparison function lives in another module (er.... Base?) and Julia can't precompile functions across modules according to this post (look at the final note in the answer by Fengyang Wang).

Back to your question: I am hesitant to post the one I generated because it is automatically generated and the output may be platform/version dependent.

from argparse.jl.

mauro3 avatar mauro3 commented on May 24, 2024

@fguevaravas, thanks for your reply! I played around with SnoopCompile a bit too and made a usrimg.jl. However, it only sped up time by about 20%. Here the usrimg.jl and scripts I used: https://gist.github.com/mauro3/f6b665ce5ab973367cfcde894bd94f71 There I write:

Does not help much. The slow part is https://gist.github.com/mauro3/f6b665ce5ab973367cfcde894bd94f71#file-snoop-include-jl-L4, but it only speeds this up from 1.5s to 1.35s. Also line 46 is not sped up.

Note snoop.jl errors here https://gist.github.com/mauro3/f6b665ce5ab973367cfcde894bd94f71#file-snoop-jl-L17. I just deleted the offending part of the "/tmp/argparse_compiles.csv" file. It could well be that that would be the part which would speed things up.

from argparse.jl.

mauro3 avatar mauro3 commented on May 24, 2024

Cool, that works, thanks!

from argparse.jl.

tjol avatar tjol commented on May 24, 2024

Has this gotten slower, or is it just really hardware dependent?

$ time julia argparse-test.jl --opt2 100 TEST
Parsed args:
  flag1  =>  false
  arg1  =>  TEST
  opt1  =>  nothing
  opt2  =>  100

real	0m4.860s
user	0m4.844s
sys	0m0.268s

$ cat argparse-test.jl 
using ArgParse

function parse_commandline()
    s = ArgParseSettings()

    @add_arg_table s begin
        "--opt1"
            help = "an option with an argument"
        "--opt2", "-o"
            help = "another option with an argument"
            arg_type = Int
            default = 0
        "--flag1"
            help = "an option without argument, i.e. a flag"
            action = :store_true
        "arg1"
            help = "a positional argument"
            required = true
    end

    return parse_args(s)
end

function main()
    parsed_args = parse_commandline()
    println("Parsed args:")
    for (arg,val) in parsed_args
        println("  $arg  =>  $val")
    end
end

main()

$ julia --version
julia version 0.6.0

$ 

from argparse.jl.

non-Jedi avatar non-Jedi commented on May 24, 2024

@fguevaravas any chance you could post an example julia script you've AOT compiled with argparse (and program.c for that script)? I'm struggling to get static compilation working when passing arguments into julia.

from argparse.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.