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

Optimize away overhead from setting up try catch if exception is impossible #34270

Closed
oxinabox opened this issue Jan 5, 2020 · 1 comment · Fixed by #51674
Closed

Optimize away overhead from setting up try catch if exception is impossible #34270

oxinabox opened this issue Jan 5, 2020 · 1 comment · Fixed by #51674
Labels
compiler:optimizer Optimization passes (mostly in base/compiler/ssair/)

Comments

@oxinabox
Copy link
Contributor

oxinabox commented Jan 5, 2020

There are a bunch of senarios, in which is should be possible to know at compile time if an exception will be thrown. (especially if we exclude unrecoverable externally triggged exceptions like out of memory).

E.g. if the code is inlined to only builtin's / LLVM intrinsics,
and there is no exception present in the code.
(maybe there could be for different iinput types, but we specialized on that so those go away).

Right now, even in the most obvious case, the compiler can't tell.
So it includes all this overhead to be ready to catch exception.

Example:

julia> function danger()
           1.0
       end
danger (generic function with 1 method)

julia> function safe()
           try
               1.0
           catch
               rethrow()
           end
       end
safe (generic function with 1 method)

julia> @btime safe()
  17.163 ns (0 allocations: 0 bytes)
1.0

julia> @btime danger()
  0.031 ns (0 allocations: 0 bytes)
1.0

Realistic case:
JuliaDiff/ChainRulesCore.jl#82

@oxinabox
Copy link
Contributor Author

oxinabox commented Nov 2, 2023

Closed by #51674

julia> @btime safe()
  0.855 ns (0 allocations: 0 bytes)
1.0

julia> @btime danger()
  0.874 ns (0 allocations: 0 bytes)
1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:optimizer Optimization passes (mostly in base/compiler/ssair/)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants