Implement error macros that come with an error message, replacing ERR_EXPLAIN. #30893
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
ERR_EXPLAIN will currently evaluate whatever you pass to it in full regardless of whether the accompanying assertion actually fails, this can be a problem if you have a debug build (or release_debug like the editor) and in a loop have an assert + an error message with some string concatenation in it.
Personally I ran into it when evaluating my new astar implementation, and realised I'd come to a 30-50% slowdown once I'd inserted
ERR_EXPLAIN
usage for nice error messages, even though no errors were occurring. (our_no_err here still using asserts, but noERR_EXPLAIN
)Solution
The error macro and the error message should be consolidated, so that for error macros that only need the error message when the assertion actually fails (like
ERR_FAIL_COND
) only then evaluate the operand for the message then, leading to less performance ache from this.And so, I've implemented alternatives to our current error macros that look like so:
ERR_FAIL_COND
->ERR_FAIL_COND_MSG
etc.Finally
I'm making this a draft PR so I can get some feedback on the implementation (the duplication might not be great, if someone has ideas for a neater implementation, I'm all ears) before I potentially sweep through the codebase and replace all usages of
ERR_EXPLAIN
, all feedback welcome!