In my app I've been having some performance issues with WebGL in Chrome. After some debugging I've found out it's because of this call to glGetError that happens very frequently:
https://github.com/floooh/sokol/blob/5f569027afa6fe6e5a5b6060aad612d8ee976b79/sokol_gfx.h#L2486
If I define SOKOL_ASSERT to just do nothing, then my application goes from about 10fps to 60fps just from removing the calls to glGetError, nothing else. So defining SOKOL_ASSERT to do nothing is currently my workaround, but I'm wondering if these checks shouldn't be made if SOKOL_DEBUG is not defined? The other call to glGetError doesn't happen if SOKOL_DEBUG is not defined so maybe this should be the same?
Anyways, I figured this is a potential performance issue for people and wanted to bring it to your attention as it can be a little tricky to debug. It's also interesting that in FireFox there there seems to be no performance decrease with all the calls to glGetError, only in Chrome.
Hmm, looks like there are different levels to this... first: release-mode builds using the sokol headers for WASM should definitely be compiled with assert-checks removed, this happens automatically in assert.h when NDEBUG is defined (see here: https://en.cppreference.com/w/cpp/error/assert), or alternatively if you redefine SOKOL_ASSERT() to be empty.
SOKOL_DEBUG also depends on NDEBUG, but SOKOL_ASSERT and SOKOL_DEBUG are not related to each other.
In sokol_gfx.h, SOKOL_DEBUG is mainly used to enable or disable the validation layer, but the validation layer is independent from glGetError() checks.
So basically: make sure that your release-mode builds are compiled with -DNDEBUG (most build systems should add this automatically though for a release-mode build).
That glGetError() drastically reduces WebGL performance is also expected, because this most likely causes a pipeline flush and render-process roundtrip each time it is called.
I'm not sure how the current situation could be improved. We'd need a warning (ideally during the build, but a runtime message would also work) when a "release build" is compiled without NDEBUG. Trouble is, how to actually detect a release build from inside the sokol headers (since that's not clearly defined, is it the absence of debug info, or the presence of optimization flags?).
Ok. Yea, I just needed to compile with -DNDEBUG. That fixes the issue for me. Thanks!
Most helpful comment
Ok. Yea, I just needed to compile with -DNDEBUG. That fixes the issue for me. Thanks!