patches: fix O(overlays) performance regression

Performance issue: editing large files (>~10KB, >2000 lines) caused
progressive slowdown regardless of VoiceOver status.

Root causes:
1. ns_zoom_find_overlay_candidate_line: called Foverlays_in on the
   entire visible buffer range on every redisplay when UAZoomEnabled().
   In files with many overlays (font-lock, hl-line, show-paren etc.)
   this was O(overlays) Lisp work per keystroke.

2. postAccessibilityNotificationsForFrame: when ns-accessibility-enabled
   is non-nil, checked BUF_OVERLAY_MODIFF every redisplay. font-lock
   bumps this on every redraw, triggering ns_ax_selected_overlay_text
   (another O(overlays) scan) for non-minibuffer windows.

Fix: Both scans now guard with MINI_WINDOW_P check. Overlay completion
frameworks (Vertico, Icomplete, Ivy) only display candidates in
minibuffer windows --- no completion framework puts selected-face
overlays in normal editing buffers. For non-minibuffer windows both
functions return immediately with zero Lisp calls.

Additionally: ns_zoom_find_child_frame_candidate is skipped when
f->child_frame_list is nil (no child frames = no Corfu popup).
This commit is contained in:
2026-03-01 04:26:12 +01:00
parent 84eb777065
commit 3d2fa7a54e
9 changed files with 87 additions and 69 deletions

View File

@@ -1,4 +1,4 @@
From ca488b10323f136b3ce2593b56e72e222bdae7d6 Mon Sep 17 00:00:00 2001
From 2a266c4f8af0277ccd5c7c1997232c2da4eb315c Mon Sep 17 00:00:00 2001
From: Martin Sukany <martin@sukany.cz>
Date: Sat, 28 Feb 2026 16:01:29 +0100
Subject: [PATCH 9/9] 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 b3bdd42..9f37c4e 100644
index 7e34286..c25abfd 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -7291,6 +7291,112 @@ visual line index for Zoom (skip whitespace-only lines
@@ -7300,6 +7300,112 @@ visual line index for Zoom (skip whitespace-only lines
return nil;
}
@@ -225,7 +225,7 @@ index b3bdd42..9f37c4e 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
@@ -9028,6 +9134,7 @@ - (void)postCompletionAnnouncementForBuffer:(struct buffer *)b
@@ -9037,6 +9143,7 @@ - (void)postCompletionAnnouncementForBuffer:(struct buffer *)b
ptrdiff_t currentOverlayStart = 0;
ptrdiff_t currentOverlayEnd = 0;
@@ -233,7 +233,7 @@ index b3bdd42..9f37c4e 100644
specpdl_ref count2 = SPECPDL_INDEX ();
record_unwind_current_buffer ();
if (b != current_buffer)
@@ -9186,6 +9293,7 @@ - (void)postCompletionAnnouncementForBuffer:(struct buffer *)b
@@ -9195,6 +9302,7 @@ - (void)postCompletionAnnouncementForBuffer:(struct buffer *)b
self.cachedCompletionOverlayEnd = 0;
self.cachedCompletionPoint = 0;
}
@@ -241,7 +241,7 @@ index b3bdd42..9f37c4e 100644
}
/* ---- Notification dispatch (main entry point) ---- */
@@ -9773,6 +9881,10 @@ - (void)dealloc
@@ -9791,6 +9899,10 @@ - (void)dealloc
#endif
[accessibilityElements release];
@@ -252,7 +252,7 @@ index b3bdd42..9f37c4e 100644
[[self menu] release];
[super dealloc];
}
@@ -12533,6 +12645,80 @@ - (id)accessibilityFocusedUIElement
@@ -12551,6 +12663,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 b3bdd42..9f37c4e 100644
- (void)postAccessibilityUpdates
{
NSTRACE ("[EmacsView postAccessibilityUpdates]");
@@ -12543,11 +12729,59 @@ - (void)postAccessibilityUpdates
@@ -12561,11 +12747,59 @@ - (void)postAccessibilityUpdates
/* Re-entrance guard: VoiceOver callbacks during notification posting
can trigger redisplay, which calls ns_update_end, which calls us