Skip to content

"try foo(); finally; end" should be optimized to "foo()" #55834

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

Open
stevengj opened this issue Sep 21, 2024 · 0 comments
Open

"try foo(); finally; end" should be optimized to "foo()" #55834

stevengj opened this issue Sep 21, 2024 · 0 comments
Labels
performance Must go faster

Comments

@stevengj
Copy link
Member

stevengj commented Sep 21, 2024

I notice a missing optimization: try foo(); finally; end is not optimized to foo(). For example, look at @code_native foo(3) for foo(x) = try; return x+1; finally; end — there is a whole bunch of overhead (_ijl_excstack_state, _ijl_enter_handler, _sigsetjmp, …) compared to x+1.

I noticed this because (related to #55754) I was looking at print(io, x) performance on IOBuffers. The fallback for print(io, x) is defined as:

function print(io::IO, x)
    lock(io)
    try
        show(io, x)
    finally
        unlock(io)
    end
    return nothing
end

but the default lock(io) and unlock(io) methods do nothing. So, on an IOBuffer at least, this whole function should be optimized to just (show(io, x); nothing), but it isn't.

@stevengj stevengj added the performance Must go faster label Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Must go faster
Projects
None yet
Development

No branches or pull requests

1 participant