Skip to content

thirdparty: add NDEBUG check before glGetErrorCode if-statement in sokol_gfx.h - #24754

Merged
spytheman merged 1 commit into
vlang:masterfrom
pisaiah:assert-patch1
Jun 19, 2025
Merged

spytheman merged 1 commit into
vlang:masterfrom
pisaiah:assert-patch1

Conversation

@pisaiah

@pisaiah pisaiah commented Jun 19, 2025 •

Copy link
Copy Markdown
Contributor

Fixes a performance drop caused by 37e5ead

When built for release, assert(x) is no-op. Commit 37e5ead, had introduced an if-block & fprintf statement to print the glGetError() code to make diagnostic easier. However, this change will execute even when assert(x) is void.

This commit provides a fix by having an ifdef check for NDEBUG, and if NDEBUG is defined then _SG_GL_CHECK_ERROR will be defined as nothing, as the result of SOKOL_ASSERT/ASSERT, would also be nothing (glibc/assert.h).

Edit:

Video of performance drop (left is after this pull, right is before):

resultss.mp4

When built for release, assert(x) becomes NOOP. Commit 37e5ead, had introduced
an if-block & fprintf statement to print the glGetError() code to make
diagnostic easier. However, this change will execute even when assert(x) is
a cast to void(0). Resulting in performance drop - which can be noticable.
(Ex: Using gg with emscripten will result in single-digit framerate)

This commit provides a fix by having an ifdef check for NDEBUG, and if NDEBUG
is defined then _SG_GL_CHECK_ERROR will be defined as nothing, as the result
of SOKOL_ASSERT -> ASSERT, would also be nothing (glibc/assert.h).
@huly-for-github

Copy link
Copy Markdown

Connected to Huly®: V_0.6-23172

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@spytheman spytheman changed the title thirdparty: Add NDEBUG check before glGetErrorCode if-statement thirdparty: add NDEBUG check before glGetErrorCode if-statement in sokol_gfx.h Jun 19, 2025
@spytheman
spytheman merged commit 125c899 into vlang:master Jun 19, 2025
@spytheman

Copy link
Copy Markdown
Contributor

Sorry for not being careful and testing with -prod too.

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.

2 participants