Is there any speed improvement from wrapping invokelatest in a try-catch?

For example, let’s say you dynamically make a module Foo:

module Foo
  nothing_here_yet = true
end

Is it worthwhile to put an invokelatest try-catch to avoid world_age bugs, while still keeping most of the speed?

try
  Foo.eval(cur_import)
catch
  Base.invokelatest(
    Foo.eval,
    cur_import
  )
end

// one related questions might be: how much does a try-catch loop hurt you (performance-wise)?

edit: more specifically, if the catch part never gets touched

I don’t know, but a try catch can be quite costly. So it might be best for you to actually test the difference.

There was a recent discussion where I found try ... catch to be a reasonable solution if the exception is thrown only occasionally. try is not very costly, catch is. @Elrod kindly provided a lot of useful benchmarks there.

2 Likes