emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: State of the overlay tree branch?


From: Sebastian Sturm
Subject: Re: State of the overlay tree branch?
Date: Fri, 23 Mar 2018 13:25:19 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

I haven't tested this very extensively yet, but artificial benchmark results are now comparable to the noverlay branch and editing seems similarly fluid. Many thanks for that! On a tangential note, removing the bottleneck now brought up another hotspot in my performance profile (less severe than the one previously reported) that seems to be due to cc-mode itself. Since I don't want to derail this thread, I'll try to implement some of the suggestions made in the "Latency profiling?" thread and come up with some reproducible data on that other issue.

On 03/23/2018 06:03 AM, Stefan Monnier wrote:
since noverlay performs so well, I guess the technical issue here is already
solved and I'll just have to wait for it to make it into the master
branch.

Yes and no: there can still be many markers (even without having any
overlays) and that poses the same problem (and the noverlays branch
doesn't change that).

I've made some further tests and found that the patch I sent indeed
doesn't help tremendously with "distance += 10" but that when we reach
"+= 50" the effect is more significant.

Could you try the patch below (ideally not just with artificial tests
but also in actual use) to see if it helps?


         Stefan


diff --git a/src/marker.c b/src/marker.c
index 7773c4fce0..6ab0d3d61e 100644
--- a/src/marker.c
+++ b/src/marker.c
@@ -133,6 +133,28 @@ CHECK_MARKER (Lisp_Object x)
    CHECK_TYPE (MARKERP (x), Qmarkerp, x);
  }
+/* When converting bytes from/to chars, we look through the list of
+   markers to try and find a good starting point (since markers keep
+   track of both bytepos and charpos at the same time).
+   But if there are many markers, it can take too much time to find a "good"
+   marker from which to start.  Worse yet: if it takes a long time and we end
+   up finding a nearby markers, we won't add a new marker to cache this
+   result, so next time around we'll have to go through this same long list
+   to (re)find this best marker.  So the further down the list of
+   markers we go, the less demanding we are w.r.t what is a good marker.
+
+   The previous code used INITIAL=50 and INCREMENT=0 and this lead to
+   really poor performance when there are many markers.
+   I haven't tried to tweak INITIAL, but my experiments on my trusty Thinkpad
+   T61 using various artificial test cases seem to suggest that INCREMENT=50
+   might be "the best compromise": it significantly improved the
+   worst case and it was rarely slower and never by much.
+
+   The asymptotic behavior is still poor, tho, so in largish buffers with many
+   overlays (e.g. 300KB and 30K overlays), it can still be a bottlneck.  */
+#define BYTECHAR_DISTANCE_INITIAL 50
+#define BYTECHAR_DISTANCE_INCREMENT 50
+
  /* Return the byte position corresponding to CHARPOS in B.  */
ptrdiff_t
@@ -141,6 +163,7 @@ buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos)
    struct Lisp_Marker *tail;
    ptrdiff_t best_above, best_above_byte;
    ptrdiff_t best_below, best_below_byte;
+  ptrdiff_t distance = BYTECHAR_DISTANCE_INITIAL;
eassert (BUF_BEG (b) <= charpos && charpos <= BUF_Z (b)); @@ -180,8 +203,10 @@ buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t 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 - best_below < 50)
+      if (best_above - best_below < distance)
        break;
+      else
+        distance += BYTECHAR_DISTANCE_INCREMENT;
      }
/* We get here if we did not exactly hit one of the known places.
@@ -293,6 +318,7 @@ buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos)
    struct Lisp_Marker *tail;
    ptrdiff_t best_above, best_above_byte;
    ptrdiff_t best_below, best_below_byte;
+  ptrdiff_t distance = BYTECHAR_DISTANCE_INITIAL;
eassert (BUF_BEG_BYTE (b) <= bytepos && bytepos <= BUF_Z_BYTE (b)); @@ -323,8 +349,10 @@ buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos)
        /* 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 - best_below < 50)
+      if (best_above - best_below < distance)
        break;
+      else
+        distance += BYTECHAR_DISTANCE_INCREMENT;
      }
/* We get here if we did not exactly hit one of the known places.



--
Sebastian Sturm
Research & Development

Phone:  +49 (0) 6155 7808977
Fax:    +49 (0) 6155 7802880
Email:  address@hidden
Web:    www.arkona-technologies.de

arkona technologies GmbH
Im Leuschnerpark 4
64347 Griesheim
Germany
Amtsgericht / Commercial Register of Darmstadt, HRB 90080
USt-ID: DE273794666
Steuernummer / Tax-ID: 007 / 228 / 19331
Geschäftsführung / Managing Director: Rainer Sturm

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this message and any attachments from your system. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

We cannot accept any responsibility for the accuracy or completeness of this message as it has been transmitted over a public network. If, despite our use of anti-virus software, a virus enters your systems in connection with the sending of the e-mail, you may not hold us liable for any damages that may possibly arise in that connection. We will accept liability which by law we cannot exclude.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]