For basically every WebGL entrypoint, the ANGLE context is enforced to be current for the executing thread. There's at this point in time the smart check to test whether the current context is already the one that we are using, through comparing against EGL_GetCurrentContext() return value. Only when not equal do we go on to call EGL_MakeCurrent(). Even the check is still expensive because it does an inefficient job of loading from thread-local storage. Because it's called on every WebGL entrypoint this becomes quite visible on profiles and a considerable amount of time is spent here. I can provide receipts later. ANGLE is internally using the `thread_local` specifier on the data structure holding the current-context value. Mesa doesn't suffer from this, and is using the `__thread` specifier, along with the `tls_model("initial-exec")` attribute. This needs confirmation on what the differentiator exactly is, after that it should be possible to decide what to change and where to do it.
Created attachment 459407 [details] WIP patch
Testing on equal WebGL load, this is the difference: Current current-context handling, through ANGLE: > CPU utilization of the WebProcess: > 2,629.68 msec task-clock # 0.657 CPUs utilized > Percentage of CPU utilization spent under and inside makeContextCurrent(): > 4.82% 0.57% WPEWebProcess libWPEWebKit-1.0.so.3.17.0 [.] WebCore::GraphicsContextGLANGLE::makeContextCurrent With a check on a thread-local variable with the tls_model("initial-exec") attribute, as implemented in the WIP patch: > CPU utilization of the WebProcess: > 17,924.20 msec task-clock # 0.597 CPUs utilized > Percentage of CPU utilization spent under and inside makeContextCurrent(): > 0.86% 0.66% WPEWebProcess libWPEWebKit-1.0.so.3.17.0 [.] WebCore::GraphicsContextGLANGLE::makeContextCurrent
Created attachment 459445 [details] Patch
Created attachment 459446 [details] Patch
Comment on attachment 459446 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=459446&action=review > Source/WebCore/ChangeLog:34 > + 'ELF Handling For Thread-Local Storage' paper by Ulrich Drepper. Reading this was good for a quick-ish summary for me: https://maskray.me/blog/2021-02-14-all-about-thread-local-storage
Created attachment 459481 [details] Patch for landing
Comment on attachment 459481 [details] Patch for landing Clearing flags on attachment: 459481 Committed r294290 (250632@trunk): <https://commits.webkit.org/250632@trunk>
All reviewed patches have been landed. Closing bug.
<rdar://problem/93399978>
Note this code has been deleted at some point. Not sure if that is OK or not, but TLS_MODEL_INITIAL_EXEC is no longer used anywhere.