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

@compile_workload fails to compile some explicit toplevel calls #37

Open
LilithHafner opened this issue Apr 8, 2024 · 0 comments
Open

Comments

@LilithHafner
Copy link
Member

When I put setup in @compile_workload, it fails to compile later steps. I suspect this is due to inlining or otherwise treating multiple lines in the compile workflow step as a single operation.

Does not compile rand(::AliasTable)

PrecompileTools.@compile_workload begin
    at = AliasTable([1.0, 2.0])
    rand(at)
end

Does compile rand(::AliasTable)

at = AliasTable([1.0, 2.0])
PrecompileTools.@compile_workload begin
    rand(at)
end

Full example

x@fedora:~/.julia/dev/AliasTables$ cat src/AliasTables.jl 
module AliasTables

using Random
using PrecompileTools

export AliasTable

struct AliasTable{T}
    x::T
end
Base.rand(x::AliasTable) = rand(x.x)

at = AliasTable([1.0, 2.0])
PrecompileTools.@compile_workload begin
    rand(at)
end

end
x@fedora:~/.julia/dev/AliasTables$ julia --project -e '@time using AliasTables; @time at = AliasTable([1.0, 2.0]); @time rand(at)'
Precompiling AliasTables...
  1 dependency successfully precompiled in 1 seconds. 6 already precompiled.
  1.115552 seconds (599.80 k allocations: 35.161 MiB, 38.56% compilation time)
  0.000001 seconds (4 allocations: 112 bytes)
  0.000016 seconds (7 allocations: 320 bytes)
x@fedora:~/.julia/dev/AliasTables$ julia --project -e '@time using AliasTables; @time at = AliasTable([1.0, 2.0]); @time rand(at)'
  0.022336 seconds (37.92 k allocations: 2.467 MiB)
  0.000002 seconds (4 allocations: 112 bytes)
  0.000011 seconds (7 allocations: 320 bytes)
x@fedora:~/.julia/dev/AliasTables$ git checkout HEAD~
HEAD is now at 87e8d9c Broken
x@fedora:~/.julia/dev/AliasTables$ cat src/AliasTables.jl 
module AliasTables

using Random
using PrecompileTools

export AliasTable

struct AliasTable{T}
    x::T
end
Base.rand(x::AliasTable) = rand(x.x)

PrecompileTools.@compile_workload begin
    at = AliasTable([1.0, 2.0])
    rand(at)
end

end
x@fedora:~/.julia/dev/AliasTables$ julia --project -e '@time using AliasTables; @time at = AliasTable([1.0, 2.0]); @time rand(at)'
Precompiling AliasTables...
  1 dependency successfully precompiled in 1 seconds. 6 already precompiled.
  0.994406 seconds (598.94 k allocations: 35.113 MiB, 43.08% compilation time)
  0.000002 seconds (4 allocations: 112 bytes)
  0.002649 seconds (236 allocations: 11.422 KiB, 99.55% compilation time)
x@fedora:~/.julia/dev/AliasTables$ julia --project -e '@time using AliasTables; @time at = AliasTable([1.0, 2.0]); @time rand(at)'
  0.022320 seconds (37.92 k allocations: 2.467 MiB)
  0.000001 seconds (4 allocations: 112 bytes)
  0.002591 seconds (236 allocations: 11.422 KiB, 99.63% compilation time)

I ran into this example when attempting to use this package to set up precompilation for AliasTables.jl (LilithHafner/AliasTables.jl#33)

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

1 participant