Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop assume-asserting logging macros #4286

Merged
merged 4 commits into from
Jan 21, 2025

Conversation

neobrain
Copy link
Member

@neobrain neobrain commented Jan 21, 2025

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.

Placing optimization hints everywhere interferes with debugging of
RelWithDebInfo builds, since the debugger won't be able to reliably
inspect variables or control flow. These hints are better placed on an
individual basis after identifying bottlenecks in a profiler.
@neobrain neobrain force-pushed the refactor_dont_assume branch from 775d29f to da58e6a Compare January 21, 2025 11:09
@neobrain
Copy link
Member Author

(For context, this came up during review of #4271 (comment), where I noticed how widely these macros had been applied.)

@alyssarosenzweig
Copy link
Collaborator

+1 to this, I've never liked this distinction and miss just regular old asserts.

(I'd also like to rename this macro to something short and lowercase, probably fex_assert. But that's a follow-on discussion.)

@Sonicadvance1 Sonicadvance1 merged commit 9def89d into FEX-Emu:main Jan 21, 2025
12 checks passed
@pmatos
Copy link
Collaborator

pmatos commented Jan 21, 2025

+1 to this, I've never liked this distinction and miss just regular old asserts.

(I'd also like to rename this macro to something short and lowercase, probably fex_assert. But that's a follow-on discussion.)

fex_assert - I like the sound of that.

@neobrain neobrain deleted the refactor_dont_assume branch January 22, 2025 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants