patches: fix standalone compilation + accessibility default + perf

Three fixes:
1. Patch 0000 now compiles standalone: replaced forward declaration
   of ns_ax_face_is_selected (defined in VoiceOver patches) with
   self-contained ns_zoom_face_is_selected in the Zoom patch.

2. ns_accessibility_enabled defaults to nil: eliminates ALL VoiceOver
   overhead (text cache rebuild, AX notifications, Mach IPC to AX
   server) when VoiceOver is not in use. Zero per-redisplay cost.
   Enable with (setq ns-accessibility-enabled t).

3. UAZoomEnabled() cached for 1s + ns_zoom_track_completion rate-
   limited to 2Hz: eliminates 150-600µs/frame of IPC overhead.
This commit is contained in:
2026-03-01 05:51:03 +01:00
parent 6b3843e0c6
commit 256263343d
11 changed files with 231 additions and 82 deletions

View File

@@ -1,4 +1,4 @@
From 8cecc655267f3adc31230a76d0d470159adc9d87 Mon Sep 17 00:00:00 2001
From e0f4378588b0fea142d707e4b51269566e50536a Mon Sep 17 00:00:00 2001
From: Martin Sukany <martin@sukany.cz>
Date: Sat, 28 Feb 2026 22:39:35 +0100
Subject: [PATCH 01/11] ns: integrate with macOS Zoom for cursor tracking
@@ -37,9 +37,9 @@ Tested on macOS 14 with Zoom enabled: cursor tracking works across
window splits, switches (C-x o), and completion frameworks.
---
etc/NEWS | 11 ++
src/nsterm.h | 6 ++
src/nsterm.m | 287 +++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 304 insertions(+)
src/nsterm.h | 6 +
src/nsterm.m | 307 +++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 324 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index ef36df5..80661a9 100644
@@ -81,10 +81,10 @@ index 7c1ee4c..ea6e7ba 100644
}
diff --git a/src/nsterm.m b/src/nsterm.m
index 74e4ad5..f7875b3 100644
index 74e4ad5..40b4bc9 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1081,6 +1081,216 @@ static NSRect constrain_frame_rect(NSRect frameRect, bool isFullscreen)
@@ -1081,6 +1081,236 @@ static NSRect constrain_frame_rect(NSRect frameRect, bool isFullscreen)
}
@@ -93,10 +93,30 @@ index 74e4ad5..f7875b3 100644
+#if defined (MAC_OS_X_VERSION_MIN_REQUIRED) \
+ && MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+
+/* Forward declaration --- defined in the VoiceOver section below.
+ Identifies faces like vertico-current, icomplete-selected-match,
+ ivy-current-match, corfu-current that mark the selected candidate. */
+static bool ns_ax_face_is_selected (Lisp_Object face);
+/* Identify faces that mark a selected completion candidate.
+ Matches vertico-current, corfu-current, icomplete-selected-match,
+ ivy-current-match, etc. by checking the face symbol name.
+ Defined here so the Zoom patch compiles independently of the
+ VoiceOver patches. */
+static bool
+ns_zoom_face_is_selected (Lisp_Object face)
+{
+ if (SYMBOLP (face))
+ {
+ const char *name = SSDATA (SYMBOL_NAME (face));
+ return (strstr (name, "current") != NULL
+ || strstr (name, "selected") != NULL
+ || strstr (name, "selection") != NULL);
+ }
+ if (CONSP (face))
+ {
+ Lisp_Object tail;
+ for (tail = face; CONSP (tail); tail = XCDR (tail))
+ if (ns_zoom_face_is_selected (XCAR (tail)))
+ return true;
+ }
+ return false;
+}
+
+/* Scan overlay before-string / after-string properties in the
+ selected window for a completion candidate with a "selected"
@@ -144,7 +164,7 @@ index 74e4ad5..f7875b3 100644
+ Lisp_Object face
+ = Fget_text_property (make_fixnum (line_start),
+ Qface, str);
+ if (ns_ax_face_is_selected (face))
+ if (ns_zoom_face_is_selected (face))
+ return line;
+ line++;
+ line_start = i + 1;
@@ -195,7 +215,7 @@ index 74e4ad5..f7875b3 100644
+ Lisp_Object face
+ = Fget_char_property (make_fixnum (pos), Qface,
+ cw->contents);
+ if (ns_ax_face_is_selected (face))
+ if (ns_zoom_face_is_selected (face))
+ {
+ unbind_to (count, Qnil);
+ *child_frame = cf;
@@ -301,7 +321,7 @@ index 74e4ad5..f7875b3 100644
static void
ns_update_end (struct frame *f)
/* --------------------------------------------------------------------------
@@ -1104,6 +1314,41 @@ static NSRect constrain_frame_rect(NSRect frameRect, bool isFullscreen)
@@ -1104,6 +1334,41 @@ static NSRect constrain_frame_rect(NSRect frameRect, bool isFullscreen)
unblock_input ();
ns_updating_frame = NULL;
@@ -343,7 +363,7 @@ index 74e4ad5..f7875b3 100644
}
static void
@@ -3232,6 +3477,45 @@ Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
@@ -3232,6 +3497,45 @@ Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
/* Prevent the cursor from being drawn outside the text area. */
r = NSIntersectionRect (r, ns_row_rect (w, glyph_row, TEXT_AREA));
@@ -389,7 +409,7 @@ index 74e4ad5..f7875b3 100644
ns_focus (f, NULL, 0);
NSGraphicsContext *ctx = [NSGraphicsContext currentContext];
@@ -8321,6 +8605,9 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f
@@ -8321,6 +8625,9 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f
windowClosing = NO;
processingCompose = NO;

View File

@@ -1,4 +1,4 @@
From a750bf8ae17dd0dd6c14a23376d012c61367227f Mon Sep 17 00:00:00 2001
From 09bb05d23a015757c7471a4b06ce8a2c852745dc Mon Sep 17 00:00:00 2001
From: Martin Sukany <martin@sukany.cz>
Date: Sat, 28 Feb 2026 12:58:11 +0100
Subject: [PATCH 02/11] ns: add accessibility base classes and text extraction
@@ -29,9 +29,9 @@ ns-accessibility-enabled.
Tested on macOS 14 Sonoma with VoiceOver 10. Builds cleanly;
no functional change (dead code until patch 5/6 wires it in).
---
src/nsterm.h | 129 +++++++++++++++
src/nsterm.m | 456 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 585 insertions(+)
src/nsterm.h | 129 ++++++++++++++
src/nsterm.m | 462 ++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 588 insertions(+), 3 deletions(-)
diff --git a/src/nsterm.h b/src/nsterm.h
index ea6e7ba..6e830de 100644
@@ -188,7 +188,7 @@ index ea6e7ba..6e830de 100644
diff --git a/src/nsterm.m b/src/nsterm.m
index f7875b3..cbfcf23 100644
index 40b4bc9..96805b9 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -46,6 +46,7 @@ Updated by Christian Limpach (chris@nice.ch)
@@ -199,7 +199,7 @@ index f7875b3..cbfcf23 100644
#include "systime.h"
#include "character.h"
#include "xwidget.h"
@@ -7140,6 +7141,430 @@ - (BOOL)fulfillService: (NSString *)name withArg: (NSString *)arg
@@ -7160,6 +7161,430 @@ - (BOOL)fulfillService: (NSString *)name withArg: (NSString *)arg
}
#endif
@@ -630,7 +630,7 @@ index f7875b3..cbfcf23 100644
/* ==========================================================================
EmacsView implementation
@@ -11599,6 +12024,28 @@ Convert an X font name (XLFD) to an NS font name.
@@ -11619,6 +12044,28 @@ Convert an X font name (XLFD) to an NS font name.
DEFSYM (Qns_drag_operation_generic, "ns-drag-operation-generic");
DEFSYM (Qns_handle_drag_motion, "ns-handle-drag-motion");
@@ -659,7 +659,16 @@ index f7875b3..cbfcf23 100644
Fput (Qalt, Qmodifier_value, make_fixnum (alt_modifier));
Fput (Qhyper, Qmodifier_value, make_fixnum (hyper_modifier));
Fput (Qmeta, Qmodifier_value, make_fixnum (meta_modifier));
@@ -11747,6 +12194,15 @@ Nil means use fullscreen the old (< 10.7) way. The old way works better with
@@ -11751,7 +12198,7 @@ Convert an X font name (XLFD) to an NS font name.
doc: /* Non-nil means to use native fullscreen on Mac OS X 10.7 and later.
Nil means use fullscreen the old (< 10.7) way. The old way works better with
multiple monitors, but lacks tool bar. This variable is ignored on
-Mac OS X < 10.7. Default is t. */);
+Mac OS X < 10.7. Default is nil. Set to t to enable VoiceOver support. */);
ns_use_native_fullscreen = YES;
ns_last_use_native_fullscreen = ns_use_native_fullscreen;
@@ -11767,10 +12214,19 @@ Nil means use fullscreen the old (< 10.7) way. The old way works better with
This variable is ignored on Mac OS X < 10.7 and GNUstep. */);
ns_use_srgb_colorspace = YES;
@@ -669,12 +678,26 @@ index f7875b3..cbfcf23 100644
+When nil, the accessibility virtual element tree is not built and no
+notifications are posted, eliminating the associated overhead.
+Requires the Cocoa (NS) build on macOS; ignored on GNUstep.
+Default is t. */);
+ ns_accessibility_enabled = YES;
+Default is nil. Set to t to enable VoiceOver support. */);
+ ns_accessibility_enabled = NO;
+
DEFVAR_BOOL ("ns-use-mwheel-acceleration",
ns_use_mwheel_acceleration,
doc: /* Non-nil means use macOS's standard mouse wheel acceleration.
-This variable is ignored on macOS < 10.7 and GNUstep. Default is t. */);
+This variable is ignored on macOS < 10.7 and GNUstep. Default is nil. Set to t to enable VoiceOver support. */);
ns_use_mwheel_acceleration = YES;
DEFVAR_LISP ("ns-mwheel-line-height", ns_mwheel_line_height,
@@ -11781,7 +12237,7 @@ Nil means use fullscreen the old (< 10.7) way. The old way works better with
DEFVAR_BOOL ("ns-use-mwheel-momentum", ns_use_mwheel_momentum,
doc: /* Non-nil means mouse wheel scrolling uses momentum.
-This variable is ignored on macOS < 10.7 and GNUstep. Default is t. */);
+This variable is ignored on macOS < 10.7 and GNUstep. Default is nil. Set to t to enable VoiceOver support. */);
ns_use_mwheel_momentum = YES;
/* TODO: Move to common code. */
--
2.43.0

View File

@@ -1,4 +1,4 @@
From cd8512d541e63f044086d1dfd2fe44069d4c09ca Mon Sep 17 00:00:00 2001
From d21a6a4a91093d5be0a9f1324250846610fc735f Mon Sep 17 00:00:00 2001
From: Martin Sukany <martin@sukany.cz>
Date: Sat, 28 Feb 2026 12:58:11 +0100
Subject: [PATCH 03/11] ns: implement buffer accessibility element (core
@@ -22,10 +22,10 @@ line-by-line navigation, word/character announcements.
1 file changed, 1097 insertions(+)
diff --git a/src/nsterm.m b/src/nsterm.m
index cbfcf23..62cc72d 100644
index 96805b9..ae4c581 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -7562,6 +7562,1103 @@ - (id)accessibilityTopLevelUIElement
@@ -7582,6 +7582,1103 @@ - (id)accessibilityTopLevelUIElement
@end

View File

@@ -1,4 +1,4 @@
From 2cb651607c84eb100729db5d4c113d7fcf4e1048 Mon Sep 17 00:00:00 2001
From f006124d3ce2f345e14baac3dd2d453abfa652e5 Mon Sep 17 00:00:00 2001
From: Martin Sukany <martin@sukany.cz>
Date: Sat, 28 Feb 2026 12:58:11 +0100
Subject: [PATCH 04/11] ns: add buffer notification dispatch and mode-line
@@ -24,10 +24,10 @@ region selection feedback, completion popups, mode-line reading.
1 file changed, 545 insertions(+)
diff --git a/src/nsterm.m b/src/nsterm.m
index 62cc72d..ab619ab 100644
index ae4c581..09f47ab 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -8659,6 +8659,551 @@ - (NSRect)accessibilityFrame
@@ -8679,6 +8679,551 @@ - (NSRect)accessibilityFrame
@end

View File

@@ -1,4 +1,4 @@
From e04d6ef8808c1e00b37fca85e6ac0a7f6104bdb7 Mon Sep 17 00:00:00 2001
From 2428a8f16873dab87284da544a7da4bbffff48a5 Mon Sep 17 00:00:00 2001
From: Martin Sukany <martin@sukany.cz>
Date: Sat, 28 Feb 2026 12:58:11 +0100
Subject: [PATCH 05/11] ns: add interactive span elements for Tab navigation
@@ -17,10 +17,10 @@ Tested on macOS 14. Verified: Tab-cycling through org-mode links,
1 file changed, 286 insertions(+)
diff --git a/src/nsterm.m b/src/nsterm.m
index ab619ab..217f4f8 100644
index 09f47ab..a056c1b 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -9204,6 +9204,292 @@ - (NSRect)accessibilityFrame
@@ -9224,6 +9224,292 @@ - (NSRect)accessibilityFrame
@end

View File

@@ -1,4 +1,4 @@
From 88bcf29875755897a3d3d4cef04e2c0044ac8b9d Mon Sep 17 00:00:00 2001
From 0f7896d526a9ad17fa34c75dd7eaf15f59e070cd Mon Sep 17 00:00:00 2001
From: Martin Sukany <martin@sukany.cz>
Date: Sat, 28 Feb 2026 12:58:11 +0100
Subject: [PATCH 06/11] ns: integrate accessibility with EmacsView and
@@ -52,10 +52,10 @@ index 80661a9..2b1f9e6 100644
** Re-introduced dictation, lost in Emacs v30 (macOS).
We lost macOS dictation in v30 when migrating to NSTextInputClient.
diff --git a/src/nsterm.m b/src/nsterm.m
index 217f4f8..9de92fb 100644
index a056c1b..92a0dde 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1350,6 +1350,9 @@ so the visual offset is (ov_line + 1) * line_h from
@@ -1370,6 +1370,9 @@ so the visual offset is (ov_line + 1) * line_h from
if (view)
ns_zoom_track_completion (f, view);
#endif /* NS_IMPL_COCOA */
@@ -65,7 +65,7 @@ index 217f4f8..9de92fb 100644
}
static void
@@ -7565,7 +7568,6 @@ - (id)accessibilityTopLevelUIElement
@@ -7585,7 +7588,6 @@ - (id)accessibilityTopLevelUIElement
@@ -73,7 +73,7 @@ index 217f4f8..9de92fb 100644
static BOOL
ns_ax_find_completion_overlay_range (struct buffer *b, ptrdiff_t point,
ptrdiff_t *out_start,
@@ -8660,7 +8662,6 @@ - (NSRect)accessibilityFrame
@@ -8680,7 +8682,6 @@ - (NSRect)accessibilityFrame
@end
@@ -81,7 +81,7 @@ index 217f4f8..9de92fb 100644
/* ===================================================================
EmacsAccessibilityBuffer (Notifications) — AX event dispatch
@@ -9205,7 +9206,6 @@ - (NSRect)accessibilityFrame
@@ -9225,7 +9226,6 @@ - (NSRect)accessibilityFrame
@end
@@ -89,7 +89,7 @@ index 217f4f8..9de92fb 100644
/* ===================================================================
EmacsAccessibilityInteractiveSpan — helpers and implementation
=================================================================== */
@@ -9535,6 +9535,7 @@ - (void)dealloc
@@ -9555,6 +9555,7 @@ - (void)dealloc
[layer release];
#endif
@@ -97,7 +97,7 @@ index 217f4f8..9de92fb 100644
[[self menu] release];
[super dealloc];
}
@@ -10883,6 +10884,32 @@ - (void)windowDidBecomeKey /* for direct calls */
@@ -10903,6 +10904,32 @@ - (void)windowDidBecomeKey /* for direct calls */
XSETFRAME (event.frame_or_window, emacsframe);
kbd_buffer_store_event (&event);
ns_send_appdefined (-1); // Kick main loop
@@ -130,7 +130,7 @@ index 217f4f8..9de92fb 100644
}
@@ -12123,6 +12150,332 @@ - (int) fullscreenState
@@ -12143,6 +12170,332 @@ - (int) fullscreenState
return fs_state;
}

View File

@@ -1,4 +1,4 @@
From 8b7858f8e43e6bd7abb58ca2da0883341b9c446a Mon Sep 17 00:00:00 2001
From babd2effe8f137292af8d7ce9cb75ec29f6d2f3d Mon Sep 17 00:00:00 2001
From: Martin Sukany <martin@sukany.cz>
Date: Sat, 28 Feb 2026 12:58:11 +0100
Subject: [PATCH 07/11] doc: add VoiceOver accessibility section to macOS

View File

@@ -1,4 +1,4 @@
From 314e2a5f406a8eb0e6909be6e07fe7e8ddd1c440 Mon Sep 17 00:00:00 2001
From a979f430547512c252320e76683a288872f4f2ff Mon Sep 17 00:00:00 2001
From: Martin Sukany <martin@sukany.cz>
Date: Sat, 28 Feb 2026 14:46:25 +0100
Subject: [PATCH 08/11] ns: announce overlay completion candidates for
@@ -62,10 +62,10 @@ index 6e830de..2102fb9 100644
@property (nonatomic, assign) BOOL cachedMarkActive;
@property (nonatomic, copy) NSString *cachedCompletionAnnouncement;
diff --git a/src/nsterm.m b/src/nsterm.m
index 9de92fb..7c44e9c 100644
index 92a0dde..aaeed33 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -7154,11 +7154,154 @@ Accessibility virtual elements (macOS / Cocoa only)
@@ -7174,11 +7174,154 @@ Accessibility virtual elements (macOS / Cocoa only)
/* ---- Helper: extract buffer text for accessibility ---- */
@@ -221,7 +221,7 @@ index 9de92fb..7c44e9c 100644
static NSString *
ns_ax_buffer_text (struct window *w, ptrdiff_t *out_start,
ns_ax_visible_run **out_runs, NSUInteger *out_nruns)
@@ -7229,7 +7372,7 @@ Accessibility virtual elements (macOS / Cocoa only)
@@ -7249,7 +7392,7 @@ Accessibility virtual elements (macOS / Cocoa only)
/* Extract this visible run's text. Use
Fbuffer_substring_no_properties which correctly handles the
@@ -230,7 +230,7 @@ index 9de92fb..7c44e9c 100644
include garbage bytes when the run spans the gap position. */
Lisp_Object lstr = Fbuffer_substring_no_properties (
make_fixnum (pos), make_fixnum (run_end));
@@ -7310,7 +7453,7 @@ Mode lines using icon fonts (e.g. doom-modeline with nerd-font)
@@ -7330,7 +7473,7 @@ Mode lines using icon fonts (e.g. doom-modeline with nerd-font)
return NSZeroRect;
/* charpos_start and charpos_len are already in buffer charpos
@@ -239,7 +239,7 @@ index 9de92fb..7c44e9c 100644
charposForAccessibilityIndex which handles invisible text. */
ptrdiff_t cp_start = charpos_start;
ptrdiff_t cp_end = cp_start + charpos_len;
@@ -7789,6 +7932,7 @@ @implementation EmacsAccessibilityBuffer
@@ -7809,6 +7952,7 @@ @implementation EmacsAccessibilityBuffer
@synthesize cachedOverlayModiff;
@synthesize cachedTextStart;
@synthesize cachedModiff;
@@ -247,7 +247,7 @@ index 9de92fb..7c44e9c 100644
@synthesize cachedPoint;
@synthesize cachedMarkActive;
@synthesize cachedCompletionAnnouncement;
@@ -7886,7 +8030,7 @@ - (void)ensureTextCache
@@ -7906,7 +8050,7 @@ - (void)ensureTextCache
NSTRACE ("EmacsAccessibilityBuffer ensureTextCache");
/* This method is only called from the main thread (AX getters
dispatch_sync to main first). Reads of cachedText/cachedTextModiff
@@ -256,7 +256,7 @@ index 9de92fb..7c44e9c 100644
write section at the end needs synchronization to protect
against concurrent reads from AX server thread. */
eassert ([NSThread isMainThread]);
@@ -7899,16 +8043,15 @@ - (void)ensureTextCache
@@ -7919,16 +8063,15 @@ - (void)ensureTextCache
return;
ptrdiff_t modiff = BUF_MODIFF (b);
@@ -279,7 +279,7 @@ index 9de92fb..7c44e9c 100644
&& cachedTextStart == BUF_BEGV (b)
&& pt >= cachedTextStart
&& (textLen == 0
@@ -7925,7 +8068,6 @@ - (void)ensureTextCache
@@ -7945,7 +8088,6 @@ - (void)ensureTextCache
[cachedText release];
cachedText = [text retain];
cachedTextModiff = modiff;
@@ -287,7 +287,7 @@ index 9de92fb..7c44e9c 100644
cachedTextStart = start;
if (visibleRuns)
@@ -7990,7 +8132,7 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
@@ -8010,7 +8152,7 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
/* Binary search: runs are sorted by charpos (ascending). Find the
run whose [charpos, charpos+length) range contains the target,
or the nearest run after an invisible gap. O(log n) instead of
@@ -296,7 +296,7 @@ index 9de92fb..7c44e9c 100644
NSUInteger lo = 0, hi = visibleRunCount;
while (lo < hi)
{
@@ -8003,7 +8145,7 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
@@ -8023,7 +8165,7 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
else
{
/* Found: charpos is inside this run. Compute UTF-16 delta
@@ -305,7 +305,7 @@ index 9de92fb..7c44e9c 100644
NSUInteger chars_in = (NSUInteger)(charpos - r->charpos);
if (chars_in == 0 || !cachedText)
return r->ax_start;
@@ -8028,10 +8170,10 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
@@ -8048,10 +8190,10 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
/* Convert accessibility string index to buffer charpos.
Safe to call from any thread: uses only cachedText (NSString) and
@@ -318,7 +318,7 @@ index 9de92fb..7c44e9c 100644
@synchronized (self)
{
if (visibleRunCount == 0)
@@ -8065,7 +8207,7 @@ - (ptrdiff_t)charposForAccessibilityIndex:(NSUInteger)ax_idx
@@ -8085,7 +8227,7 @@ - (ptrdiff_t)charposForAccessibilityIndex:(NSUInteger)ax_idx
return cp;
}
}
@@ -327,7 +327,7 @@ index 9de92fb..7c44e9c 100644
if (lo > 0)
{
ns_ax_visible_run *last = &visibleRuns[visibleRunCount - 1];
@@ -8087,7 +8229,7 @@ - (ptrdiff_t)charposForAccessibilityIndex:(NSUInteger)ax_idx
@@ -8107,7 +8249,7 @@ - (ptrdiff_t)charposForAccessibilityIndex:(NSUInteger)ax_idx
deadlocking the AX server thread. This is prevented by:
1. validWindow checks WINDOW_LIVE_P and BUFFERP before every
@@ -336,7 +336,7 @@ index 9de92fb..7c44e9c 100644
2. All dispatch_sync blocks run on the main thread where no
concurrent Lisp code can modify state between checks.
3. block_input prevents timer events and process output from
@@ -8441,6 +8583,50 @@ - (NSInteger)accessibilityInsertionPointLineNumber
@@ -8461,6 +8603,50 @@ - (NSInteger)accessibilityInsertionPointLineNumber
return [self lineForAXIndex:point_idx];
}
@@ -387,7 +387,7 @@ index 9de92fb..7c44e9c 100644
- (NSRange)accessibilityRangeForLine:(NSInteger)line
{
if (![NSThread isMainThread])
@@ -8663,7 +8849,7 @@ - (NSRect)accessibilityFrame
@@ -8683,7 +8869,7 @@ - (NSRect)accessibilityFrame
/* ===================================================================
@@ -396,7 +396,7 @@ index 9de92fb..7c44e9c 100644
These methods notify VoiceOver of text and selection changes.
Called from the redisplay cycle (postAccessibilityUpdates).
@@ -8678,7 +8864,7 @@ - (void)postTextChangedNotification:(ptrdiff_t)point
@@ -8698,7 +8884,7 @@ - (void)postTextChangedNotification:(ptrdiff_t)point
if (point > self.cachedPoint
&& point - self.cachedPoint == 1)
{
@@ -405,7 +405,7 @@ index 9de92fb..7c44e9c 100644
[self invalidateTextCache];
[self ensureTextCache];
if (cachedText)
@@ -8697,7 +8883,7 @@ - (void)postTextChangedNotification:(ptrdiff_t)point
@@ -8717,7 +8903,7 @@ - (void)postTextChangedNotification:(ptrdiff_t)point
/* Update cachedPoint here so the selection-move branch does NOT
fire for point changes caused by edits. WebKit and Chromium
never send both ValueChanged and SelectedTextChanged for the
@@ -414,7 +414,7 @@ index 9de92fb..7c44e9c 100644
self.cachedPoint = point;
NSDictionary *change = @{
@@ -9030,16 +9216,83 @@ - (void)postAccessibilityNotificationsForFrame:(struct frame *)f
@@ -9050,16 +9236,83 @@ - (void)postAccessibilityNotificationsForFrame:(struct frame *)f
BOOL markActive = !NILP (BVAR (b, mark_active));
/* --- Text changed (edit) --- */
@@ -502,7 +502,7 @@ index 9de92fb..7c44e9c 100644
{
ptrdiff_t oldPoint = self.cachedPoint;
BOOL oldMarkActive = self.cachedMarkActive;
@@ -9207,7 +9460,7 @@ - (NSRect)accessibilityFrame
@@ -9227,7 +9480,7 @@ - (NSRect)accessibilityFrame
/* ===================================================================
@@ -511,7 +511,7 @@ index 9de92fb..7c44e9c 100644
=================================================================== */
/* Scan visible range of window W for interactive spans.
@@ -9415,7 +9668,7 @@ - (void) setAccessibilityFocused: (BOOL) focused
@@ -9435,7 +9688,7 @@ - (void) setAccessibilityFocused: (BOOL) focused
dispatch_async (dispatch_get_main_queue (), ^{
/* lwin is a Lisp_Object captured by value. This is GC-safe
because Lisp_Objects are tagged integers/pointers that
@@ -520,7 +520,7 @@ index 9de92fb..7c44e9c 100644
Emacs. The WINDOW_LIVE_P check below guards against the
window being deleted between capture and execution. */
if (!WINDOWP (lwin) || NILP (Fwindow_live_p (lwin)))
@@ -9441,7 +9694,7 @@ - (void) setAccessibilityFocused: (BOOL) focused
@@ -9461,7 +9714,7 @@ - (void) setAccessibilityFocused: (BOOL) focused
@end
@@ -529,7 +529,7 @@ index 9de92fb..7c44e9c 100644
Methods are kept here (same .m file) so they access the ivars
declared in the @interface ivar block. */
@implementation EmacsAccessibilityBuffer (InteractiveSpans)
@@ -12166,7 +12419,7 @@ - (int) fullscreenState
@@ -12186,7 +12439,7 @@ - (int) fullscreenState
if (WINDOW_LEAF_P (w))
{
@@ -538,7 +538,7 @@ index 9de92fb..7c44e9c 100644
EmacsAccessibilityBuffer *elem
= [existing objectForKey:[NSValue valueWithPointer:w]];
if (!elem)
@@ -12200,7 +12453,7 @@ - (int) fullscreenState
@@ -12220,7 +12473,7 @@ - (int) fullscreenState
}
else
{
@@ -547,7 +547,7 @@ index 9de92fb..7c44e9c 100644
Lisp_Object child = w->contents;
while (!NILP (child))
{
@@ -12312,7 +12565,7 @@ - (void)postAccessibilityUpdates
@@ -12332,7 +12585,7 @@ - (void)postAccessibilityUpdates
accessibilityUpdating = YES;
/* Detect window tree change (split, delete, new buffer). Compare
@@ -556,7 +556,7 @@ index 9de92fb..7c44e9c 100644
Lisp_Object curRoot = FRAME_ROOT_WINDOW (emacsframe);
if (!EQ (curRoot, lastRootWindow))
{
@@ -12321,12 +12574,12 @@ - (void)postAccessibilityUpdates
@@ -12341,12 +12594,12 @@ - (void)postAccessibilityUpdates
}
/* If tree is stale, rebuild FIRST so we don't iterate freed

View File

@@ -1,4 +1,4 @@
From a75ee6aff3734bd053865b3df734b75642f7305e Mon Sep 17 00:00:00 2001
From 5edae69b987f3234d4545d8c77f89f5dc4201e03 Mon Sep 17 00:00:00 2001
From: Martin Sukany <martin@sukany.cz>
Date: Sat, 28 Feb 2026 16:01:29 +0100
Subject: [PATCH 09/11] ns: announce child frame completion candidates for
@@ -109,10 +109,10 @@ index 2102fb9..dd98d56 100644
@end
diff --git a/src/nsterm.m b/src/nsterm.m
index 7c44e9c..12c451b 100644
index aaeed33..d576512 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -7298,6 +7298,112 @@ visual line index for Zoom (skip whitespace-only lines
@@ -7318,6 +7318,112 @@ visual line index for Zoom (skip whitespace-only lines
return nil;
}
@@ -225,7 +225,7 @@ index 7c44e9c..12c451b 100644
/* Build accessibility text for window W, skipping invisible text.
Populates *OUT_START with the buffer start charpos.
Populates *OUT_RUNS with an array of visible runs and *OUT_NRUNS
@@ -9035,6 +9141,7 @@ - (void)postCompletionAnnouncementForBuffer:(struct buffer *)b
@@ -9055,6 +9161,7 @@ - (void)postCompletionAnnouncementForBuffer:(struct buffer *)b
ptrdiff_t currentOverlayStart = 0;
ptrdiff_t currentOverlayEnd = 0;
@@ -233,7 +233,7 @@ index 7c44e9c..12c451b 100644
specpdl_ref count2 = SPECPDL_INDEX ();
record_unwind_current_buffer ();
if (b != current_buffer)
@@ -9193,6 +9300,7 @@ - (void)postCompletionAnnouncementForBuffer:(struct buffer *)b
@@ -9213,6 +9320,7 @@ - (void)postCompletionAnnouncementForBuffer:(struct buffer *)b
self.cachedCompletionOverlayEnd = 0;
self.cachedCompletionPoint = 0;
}
@@ -241,7 +241,7 @@ index 7c44e9c..12c451b 100644
}
/* ---- Notification dispatch (main entry point) ---- */
@@ -9789,6 +9897,10 @@ - (void)dealloc
@@ -9809,6 +9917,10 @@ - (void)dealloc
#endif
[accessibilityElements release];
@@ -252,7 +252,7 @@ index 7c44e9c..12c451b 100644
[[self menu] release];
[super dealloc];
}
@@ -12549,6 +12661,80 @@ - (id)accessibilityFocusedUIElement
@@ -12569,6 +12681,80 @@ - (id)accessibilityFocusedUIElement
The existing elements carry cached state (modiff, point) from the
previous redisplay cycle. Rebuilding first would create fresh
elements with current values, making change detection impossible. */
@@ -333,7 +333,7 @@ index 7c44e9c..12c451b 100644
- (void)postAccessibilityUpdates
{
NSTRACE ("[EmacsView postAccessibilityUpdates]");
@@ -12559,11 +12745,59 @@ - (void)postAccessibilityUpdates
@@ -12579,11 +12765,59 @@ - (void)postAccessibilityUpdates
/* Re-entrance guard: VoiceOver callbacks during notification posting
can trigger redisplay, which calls ns_update_end, which calls us

View File

@@ -1,4 +1,4 @@
From 1d67b993dc9072f36a7742fc3d284b7bd935a84d Mon Sep 17 00:00:00 2001
From ec00458c25db0fbf4af2eeb4c88e59c0af7d2063 Mon Sep 17 00:00:00 2001
From: Daneel <daneel@sukany.cz>
Date: Sun, 1 Mar 2026 04:56:16 +0100
Subject: [PATCH 10/11] perf: use BUF_CHARS_MODIFF for AX text cache validity
@@ -26,10 +26,10 @@ check would prevent those announcements from firing.
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/src/nsterm.m b/src/nsterm.m
index 12c451b..e3f9466 100644
index d576512..1da6f41 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -8148,16 +8148,25 @@ - (void)ensureTextCache
@@ -8168,16 +8168,25 @@ - (void)ensureTextCache
if (!b)
return;
@@ -63,7 +63,7 @@ index 12c451b..e3f9466 100644
&& cachedTextStart == BUF_BEGV (b)
&& pt >= cachedTextStart
&& (textLen == 0
@@ -8173,7 +8182,7 @@ included in the cached AX text (it is handled separately via
@@ -8193,7 +8202,7 @@ included in the cached AX text (it is handled separately via
{
[cachedText release];
cachedText = [text retain];

View File

@@ -0,0 +1,106 @@
From 36b206ece4323fb4a81b92d056291b4835ffd907 Mon Sep 17 00:00:00 2001
From: Daneel <daneel@sukany.cz>
Date: Sun, 1 Mar 2026 05:50:40 +0100
Subject: [PATCH 11/11] perf: cache UAZoomEnabled() result and rate-limit
completion tracking
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
UAZoomEnabled() is a synchronous Mach IPC roundtrip to the macOS
Accessibility server (~50-200 µs per call). Called from
ns_draw_window_cursor, ns_update_end and ns_zoom_track_completion
on every redisplay cycle, the total cost reaches ~150-600 µs/frame.
At 60 fps this adds 9-36 ms/s of IPC overhead that blocks the main
thread and amplifies Emacs's inherent per-frame redisplay cost.
* src/nsterm.m (ns_zoom_cached_enabled, ns_zoom_cache_time): New
static variables for caching the UAZoomEnabled() result.
(ns_zoom_enabled_p): New function. Cache UAZoomEnabled() for one
second using CFAbsoluteTimeGetCurrent() (a near-free VDSO read).
Zoom state changes only on explicit user action in System Settings.
(ns_zoom_track_completion): Rate-limit to 2 Hz. Completion state
changes at human interaction speed; 500 ms polling is imperceptible.
---
src/nsterm.m | 40 +++++++++++++++++++++++++++++++++++++---
1 file changed, 37 insertions(+), 3 deletions(-)
diff --git a/src/nsterm.m b/src/nsterm.m
index 1da6f41..27607c0 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1087,6 +1087,29 @@ static NSRect constrain_frame_rect(NSRect frameRect, bool isFullscreen)
#if defined (MAC_OS_X_VERSION_MIN_REQUIRED) \
&& MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+/* Cached wrapper around ns_zoom_enabled_p ().
+ ns_zoom_enabled_p () performs a synchronous Mach IPC roundtrip to the
+ macOS Accessibility server (~50-200 µs per call). With call sites
+ in ns_draw_window_cursor, ns_update_end, and ns_zoom_track_completion,
+ the overhead accumulates to ~150-600 µs per redisplay cycle. Zoom
+ state changes only on explicit user action in System Settings, so a
+ 1-second TTL is safe and indistinguishable from querying every frame.
+ Uses CFAbsoluteTimeGetCurrent() (~5 ns, a VDSO read) for timing. */
+static BOOL ns_zoom_cached_enabled;
+static CFAbsoluteTime ns_zoom_cache_time;
+
+static BOOL
+ns_zoom_enabled_p (void)
+{
+ CFAbsoluteTime now = CFAbsoluteTimeGetCurrent ();
+ if (now - ns_zoom_cache_time > 1.0)
+ {
+ ns_zoom_cached_enabled = UAZoomEnabled ();
+ ns_zoom_cache_time = now;
+ }
+ return ns_zoom_cached_enabled;
+}
+
/* Identify faces that mark a selected completion candidate.
Matches vertico-current, corfu-current, icomplete-selected-match,
ivy-current-match, etc. by checking the face symbol name.
@@ -1235,11 +1258,22 @@ If a completion candidate is selected (overlay or child frame),
static void
ns_zoom_track_completion (struct frame *f, EmacsView *view)
{
- if (!UAZoomEnabled ())
+ if (!ns_zoom_enabled_p ())
return;
if (!WINDOWP (f->selected_window))
return;
+ /* Rate-limit completion scan to 2 Hz. Completion state changes at
+ human interaction speed; checking every 500 ms eliminates
+ per-redisplay FOR_EACH_FRAME overhead with no perceptible lag. */
+ {
+ static CFAbsoluteTime last_check;
+ CFAbsoluteTime now = CFAbsoluteTimeGetCurrent ();
+ if (now - last_check < 0.5)
+ return;
+ last_check = now;
+ }
+
specpdl_ref count = SPECPDL_INDEX ();
record_unwind_current_buffer ();
@@ -1343,7 +1377,7 @@ so the visual offset is (ov_line + 1) * line_h from
(zoomCursorUpdated is NO). */
#if defined (MAC_OS_X_VERSION_MIN_REQUIRED) \
&& MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
- if (view && !view->zoomCursorUpdated && UAZoomEnabled ()
+ if (view && !view->zoomCursorUpdated && ns_zoom_enabled_p ()
&& !NSIsEmptyRect (view->lastCursorRect))
{
NSRect r = view->lastCursorRect;
@@ -3520,7 +3554,7 @@ EmacsView pixels (AppKit, flipped, top-left origin)
#if defined (MAC_OS_X_VERSION_MIN_REQUIRED) \
&& MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
- if (UAZoomEnabled ())
+ if (ns_zoom_enabled_p ())
{
NSRect windowRect = [view convertRect:r toView:nil];
NSRect screenRect
--
2.43.0