Drop assume-asserting logging macros #4286
Merged
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.
Replacing debug-only assertions with
__builtin_assume
in optimizing builds seems like a free performance-win at first, but it turns out to be a footgun with no practical upside: The binary size reduction I measured is 0.03% (a factor of 0.0003).One big problem is that these hints interfere with debugging of non-assertion builds. Since the compiler generates code as-if the condition were true, a debugger will print wrong variable values or have erratic source stepping behavior. This can even apply to Debug builds, since FEX uses a dedicated
ASSERTIONS_ENABLED
macro.Even debug printfs will print misleading information, which isn't obvious when your assumption is hidden in an innocent-looking macro that's barely distinguished from the non-hinting one.
As a future guideline, optimization hints should instead be placed intentionally after identifying bottlenecks in a profiler to communicate where hotspots are located and what invariants their efficient execution relies on.