How to optimise Debug.assert #5473
Replies: 4 comments 3 replies
-
@willeastcott @slimbuck @kungfooman - thoughts? |
Beta Was this translation helpful? Give feedback.
-
@kungfooman - thanks! Yes, that was the first idea I looked at (and ChatGPT suggested), but it didn't feel clean enough, but perhaps it's fine. At the moment it feels a lot better than the suggestion I had in the initial post. Any other ideas? If not, I'll go ahead with this I think. |
Beta Was this translation helpful? Give feedback.
-
Yep agree with @kungfooman 👍🏻 |
Beta Was this translation helpful? Give feedback.
-
hey mvaligursky, in my opinin we can try "Instead of giving Debug the full message right away, we give Debug instructions on how to create the message, but only when it’s really needed.function check (condition, makeMessage) { if (!condition) {// If the condition is not true (false) |
Beta Was this translation helpful? Give feedback.
-
currently we have this implementation
And typically it's called like this:
The problem here is that the templated string gets expanded before being passed to the assert function, which is expensive if this call is used in hot functions - we get lots of string concatenations.
Ideally, this would only take place when the assertion condition is false, which is when the string is logged out.
What are the options?
One I see is this:
which works, but gives me this lint warning:
Is there something better?
Beta Was this translation helpful? Give feedback.
All reactions