Skip to content
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

Extreme precompilation time #32

Open
oxinabox opened this issue Aug 23, 2021 · 5 comments
Open

Extreme precompilation time #32

oxinabox opened this issue Aug 23, 2021 · 5 comments

Comments

@oxinabox
Copy link

I am getting some very long precompilation time.
and AFAICT it is just my 1 parser

  1 dependency successfully precompiled in 46 seconds (39 already precompiled)

CombinedParsers.jl is my only direct dependency,
The parser in question is:

struct Binder
    name::Symbol
    type
    implicit::Bool
end

struct ArrayBuilder{T,N}
    size::Vector{Union{Symbol,Int}}
end
ArrayBuilder{T}(size) where T = ArrayBuilder{T,length(size)}(size)

@with_names begin
    name = map(Symbol, !re"arg\d+")
    scalar_type = Either{Any}(Any[
        parser("f32"=>Float32),
        parser("f64"=>Float64),
        parser("i32"=>Int32),
        parser("i64"=>Int64),
        parser("i8"=>Int8),
    ])
    size_ele = Numeric(Int) | name
    sizes = join(Repeat(size_ele),",")
    array_type = map(scalar_type * "[" * sizes * "]") do (T, _, sz, _)
        ArrayBuilder{T}(sz)
    end
    type = Either{Any}(Any[array_type, scalar_type])
    implicit = parser("?"=>true) | false
    arg_sig = map(implicit * name * ":" * type) do (i, n, _ , t)
        Binder(n, t, i)
    end
    arg_sigs = join(Repeat(arg_sig),",")
end
@oxinabox
Copy link
Author

Moving it into a function seemed to help immensely

@gkappler
Copy link
Owner

gkappler commented Sep 1, 2021

Thanks for the observation and pointer.
It's also my observation that defining functions that construct parsers speeds up precompilation compared to defining parser variables.

For a systematic optimization ChrisRackauckas note will probably be very instructive:
https://discourse.julialang.org/t/22-seconds-to-3-and-now-more-lets-fix-all-of-the-differentialequations-jl-universe-compile-times/66313

Unsure when I will get to systematic investigation and optimization again, after left recursion and tracing.

@Amval
Copy link

Amval commented Oct 5, 2021

I was experiencing these problems as well. In particular, I am trying to implement a parser for OWL: https://www.w3.org/TR/owl2-syntax/#Definitions_of_OWL_2_Constructs

The first problem is the lack of left recursivity, but I only need to parse a less expressive subset, so it's fine.

The second problem is the extremely long precompilation times. If you wrap the parser in a function, it disappears completely. But you pay it when you run the function for the first time. And I must be doing something that increases them like crazy because I went from something like 45s to...40 minutes!!

I think it's because I am having tons of complex return types and I probably should change approaches. I will report back once I try a different approach to the parser.

PS: I really like the library, though. It's really expressive and readable.

@oxinabox
Copy link
Author

oxinabox commented Oct 5, 2021

40 minute compile time has to be a bug in Julia itself.
Open an issue with me on JuliaLang/julia

@Amval
Copy link

Amval commented Oct 11, 2021

@gkappler This comment from JeffBezanson seems relevant to the problem: JuliaLang/julia#42502 (comment)

I am struggling with finding an approach that works. Is there a way to deal with this to reduce complexity of the return type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants