From a6ff6268bdc42a7dfedc6729d4232a2ae149da56 Mon Sep 17 00:00:00 2001 Message-Id: From: Ihor Radchenko Date: Sun, 23 Apr 2023 21:31:46 +0200 Subject: [PATCH] * src/marker.c (buf_bytepos_to_charpos): Limit marker search Limit searching across buffer markers to first 50 markers and thus avoid performance scaling with the number of markers. I got 5x `re-search-forward' speed improvement in my setup with this dumb change. --- src/marker.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/marker.c b/src/marker.c index e42c49a5434..008a76c49e6 100644 --- a/src/marker.c +++ b/src/marker.c @@ -348,8 +348,10 @@ buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos) if (b == cached_buffer && BUF_MODIFF (b) == cached_modiff) CONSIDER (cached_bytepos, cached_charpos); - for (tail = BUF_MARKERS (b); tail; tail = tail->next) + int i = 0; + for (tail = BUF_MARKERS (b); tail && i < 50; tail = tail->next) { + i++; CONSIDER (tail->bytepos, tail->charpos); /* If we are down to a range of 50 chars, -- 2.40.0