From: Ihor Radchenko <yantar92@posteo.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 63040@debbugs.gnu.org
Subject: bug#63040: 30.0.50; Performance of buf_bytepos_to_charpos when a buffer has large number of markers
Date: Mon, 24 Apr 2023 06:36:07 +0000 [thread overview]
Message-ID: <87bkjdzt0o.fsf@localhost> (raw)
In-Reply-To: <83wn22xbj9.fsf@gnu.org>
Eli Zaretskii <eliz@gnu.org> writes:
>> I am sure that my dumb approach is not the best way to improve the
>> performance, but this place in buf_bytepos_to_charpos is clearly
>> something that can be optimized.
>
> Interesting. Would it be possible to show the effect of different
> values of the cut-off on the performance, so we could decide which
> value to use?
I can do such test, but I do not think that playing with cut off is the
best approach here.
The full code in question is below and there is already existing
condition to cut the marker loop early based on the distance from
best_above to the requested bytepos. So, another approach could be
playing with BYTECHAR_DISTANCE_INCREMENT. Now, it is clearly not
efficient enough for my large file. (Note that I expressed similar idea
in another discussion and was pointed exactly to this existing condition)
Further, the later code creates markers to cache recent results and
cutting too early may waste this cache. Another idea could be moving the
cache markers into a separate array, so that we can examine them without
mixing with all other buffer markers. I am not sure if it is feasible
though.
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,
don't bother checking any other markers;
scan the intervening chars directly now. */
if (best_above - bytepos < distance
|| bytepos - best_below < distance)
break;
else
distance += BYTECHAR_DISTANCE_INCREMENT;
}
/* We get here if we did not exactly hit one of the known places.
We have one known above and one known below.
Scan, counting characters, from whichever one is closer. */
if (bytepos - best_below_byte < best_above_byte - bytepos)
{
...
/* If this position is quite far from the nearest known position,
cache the correspondence by creating a marker here.
It will last until the next GC.
But don't do it if BUF_MARKERS is nil;
that is a signal from Fset_buffer_multibyte. */
if (record && BUF_MARKERS (b))
build_marker (b, best_below, best_below_byte);
...
return best_below;
}
else
{
...
if (record && BUF_MARKERS (b))
build_marker (b, best_above, best_above_byte);
...
return best_above;
}
}
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
next prev parent reply other threads:[~2023-04-24 6:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-23 19:41 bug#63040: 30.0.50; Performance of buf_bytepos_to_charpos when a buffer has large number of markers Ihor Radchenko
2023-04-24 2:24 ` Eli Zaretskii
2023-04-24 6:36 ` Ihor Radchenko [this message]
2023-04-24 11:02 ` Eli Zaretskii
2023-04-24 11:03 ` Eli Zaretskii
2023-04-24 11:17 ` Ihor Radchenko
2024-06-25 21:04 ` Stefan Monnier
2024-06-26 12:47 ` Ihor Radchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bkjdzt0o.fsf@localhost \
--to=yantar92@posteo.net \
--cc=63040@debbugs.gnu.org \
--cc=eliz@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.