opened 02:19PM - 21 Sep 24 UTC
      
      
     
    
        
          performance
        
    
   
 
  
    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 `IOBuffer`s.  The fallback for `print(io, x)` is [defined as](https://github.com/JuliaLang/julia/blob/911e02558d0c145a192facd28808b68e157aa5af/base/strings/io.jl#L32-L40):
```jl
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](https://github.com/JuliaLang/julia/blob/911e02558d0c145a192facd28808b68e157aa5af/base/io.jl#L26-L27) do `nothing`.   So, on an `IOBuffer` at least, this whole function *should* be optimized to just `(show(io, x); nothing)`, but it isn't.