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

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

Closed
tkf opened this issue Oct 11, 2021 · 7 comments · Fixed by #42635
Closed

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

tkf opened this issue Oct 11, 2021 · 7 comments · Fixed by #42635
Assignees
Labels
compiler:latency Compiler latency regression Regression in behavior compared to a previous version
Milestone

Comments

@tkf
Copy link
Member

tkf commented Oct 11, 2021

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).

@tkf tkf added the regression Regression in behavior compared to a previous version label Oct 11, 2021
@tkf tkf added this to the 1.7 milestone Oct 11, 2021
@tkf
Copy link
Member Author

tkf commented Oct 11, 2021

It's a rather drastic regression so I just put in the milestone. But please feel free to remove it if not appropriate.

@vchuravy
Copy link
Member

Can you bisect?

@tkf
Copy link
Member Author

tkf commented Oct 11, 2021

Yeah, I think I can

@tkf
Copy link
Member Author

tkf commented Oct 11, 2021

It looks like #41827 introduced the issue.

@JeffBezanson JeffBezanson added the compiler:latency Compiler latency label Oct 12, 2021
@JeffBezanson
Copy link
Member

Looks like O(n^2) attribute list lookup?

@vtjnash
Copy link
Member

vtjnash commented Oct 12, 2021

Nah, just O(2^32). If there are no attributes, LLVM reports that there are instead 2^32 + 1. They delete this foot-gun in the next LLVM version.

@mwlidar
Copy link

mwlidar commented Oct 13, 2021

Ah, now it becomes clear why my QML.jl based GUI application takes ages to compile and start since I upgraded to julia 1.6.3!!!
Does anyone have an idea how to hack around this until the new LLVM version gets merged? Maybe by adding a fake attribute or something like that?

@KristofferC KristofferC modified the milestones: 1.7, 1.6.4 Oct 13, 2021
@JeffBezanson JeffBezanson self-assigned this Oct 13, 2021
KristofferC pushed a commit that referenced this issue Oct 18, 2021
KristofferC pushed a commit that referenced this issue Oct 19, 2021
KristofferC pushed a commit that referenced this issue Nov 11, 2021
staticfloat pushed a commit that referenced this issue Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:latency Compiler latency regression Regression in behavior compared to a previous version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants