Skip to content

Creating @cfunction from a closure takes a long time in compilation #42590

@tkf

Description

@tkf

Edit: it looks like #41827 (which is a bug fix) introduced the performance regression.

Running the script below shows that demo_slow takes about 30 seconds to compile in Julia 1.8-DEV (9a2e763) and 1.7.0-rc1 (9eade61) while it completes in a few tens of milliseconds in Julia 1.7.0-beta4.2 (642719e) and 1.6.

as_cfunction(f) = @cfunction($f, Cvoid, ())

function demo_fast()
    as_cfunction() do
        global GLOBAL = 1
        return
    end
end

function demo_slow()
    x = 0
    as_cfunction() do
        global GLOBAL = x
        return
    end
end

@info "Calling `demo_fast`..."
@time demo_fast()
@info "Calling `demo_slow`..."
t0 = time_ns()
@time demo_slow()
@show (time_ns() - t0) / 1e9

includeing the above script in @profile suggests that Julia spends most of the time in gen_cfun_wrapper (and _ZNK4llvm13AttributeList13hasAttributesEj called from it).

Metadata

Metadata

Assignees

Labels

latencyLatencyregressionRegression in behavior compared to a previous version

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions