Stream: helpdesk (published)

Topic: ✔ Julia spending lots of time in `string_n`


view this post on Zulip Sukera (Jun 11 2023 at 06:08):

the stacktrace has cityindex:62, which is likely where your function definition originally is?

view this post on Zulip Sukera (Jun 11 2023 at 06:09):

if so, yes, the interpolation ALWAYS happens, not just when the error is thrown

view this post on Zulip Sukera (Jun 11 2023 at 06:11):

note also the docstring of @assert:

   Warning
  
    An assert might be disabled at various optimization levels. Assert should therefore only be used as a
    debugging tool and not used for authentication verification (e.g., verifying passwords), nor should
    side effects needed for the function to work correctly be used inside of asserts.

So at various optimization levels, the @assert may be removed entirely, leading to a wrong result. I'd suggest the pattern

isnothing(i) || throw(ArgumentError(LazyString("City ", c, " not found"))

which will stay in your code across optimization levels and only interpolate the string when the error is actually thrown.

view this post on Zulip Notification Bot (Jun 11 2023 at 11:31):

Laura Demkowicz-Duffy has marked this topic as resolved.

view this post on Zulip Notification Bot (Jun 11 2023 at 11:31):

Laura Demkowicz-Duffy has marked this topic as resolved.


Last updated: Oct 02 2023 at 04:34 UTC