From 6a6b0b47a384d07bd9ede933aa0085396a604158 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 22 Oct 2025 13:35:02 +0530 Subject: [PATCH] Micro-optimize display link callback Use a GCD block rather than a runtime selector with a boxed number --- glfw/cocoa_displaylink.m | 8 +++----- glfw/cocoa_init.m | 7 ------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/glfw/cocoa_displaylink.m b/glfw/cocoa_displaylink.m index 3f2a1a44b..47c0b3011 100644 --- a/glfw/cocoa_displaylink.m +++ b/glfw/cocoa_displaylink.m @@ -84,11 +84,9 @@ CGDirectDisplayID displayID = entry->displayID; if (should_dispatch) entry->pending_dispatch = true; os_unfair_lock_unlock(lock); - if (should_dispatch) { - NSNumber *arg = [NSNumber numberWithUnsignedInt:displayID]; - [NSApp performSelectorOnMainThread:@selector(render_frame_received:) withObject:arg waitUntilDone:NO]; - [arg release]; - } + if (should_dispatch) dispatch_async(dispatch_get_main_queue(), ^{ + _glfwDispatchRenderFrame(displayID); + }); } return kCVReturnSuccess; } diff --git a/glfw/cocoa_init.m b/glfw/cocoa_init.m index b03c770b9..296949eed 100644 --- a/glfw/cocoa_init.m +++ b/glfw/cocoa_init.m @@ -500,7 +500,6 @@ - (void)applicationDidHide:(NSNotification *)notification @interface GLFWApplication : NSApplication - (void)tick_callback; -- (void)render_frame_received:(id)displayIDAsID; @end @implementation GLFWApplication @@ -509,12 +508,6 @@ - (void)tick_callback _glfwDispatchTickCallback(); } -- (void)render_frame_received:(id)displayIDAsID -{ - CGDirectDisplayID displayID = [(NSNumber*)displayIDAsID unsignedIntValue]; - _glfwDispatchRenderFrame(displayID); -} - @end