From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: dalanicolai Newsgroups: gmane.emacs.devel Subject: Re: displaying margins leads to Emacs hanging Date: Sat, 25 Feb 2023 14:17:24 +0100 Message-ID: References: <83edqen95b.fsf@gnu.org> <838rgmn6y4.fsf@gnu.org> <83bklikogf.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000bf69cf05f5861141" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3249"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Feb 25 14:18:40 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pVuRj-0000dE-9Y for ged-emacs-devel@m.gmane-mx.org; Sat, 25 Feb 2023 14:18:39 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVuQs-00044H-4q; Sat, 25 Feb 2023 08:17:46 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pVuQp-00042i-Jr for emacs-devel@gnu.org; Sat, 25 Feb 2023 08:17:43 -0500 Original-Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pVuQk-0005fS-22; Sat, 25 Feb 2023 08:17:43 -0500 Original-Received: by mail-wr1-x433.google.com with SMTP id bt28so1856917wrb.8; Sat, 25 Feb 2023 05:17:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=6wS0ki92N6u9IiwfY7vGKrg8x6PBZLouUUMpfz5PbFI=; b=NQsOLDgsbyoiOQCaStEX8AP5JbJw8bCLVAsM2li42JNONlR7ILVUZyj98wFNu7R7ty s3ZktoN1ojTfEqpfmVjba5OT0jy9wXTcqRP7m8G+rd9leO5goplPpUha0yFThJu4P5zq NzBdTKXCMvBoKRMY+gmSD9i6UCQVb76t0Ij5912t8C/f+q4+0ZclrfQRmJuUtUy0sm/u aKqlHa71Zt2AQ7mj+k9DYx8C6Dp7q42Ax0ZcvB9GHWp3N4ls2zeI+bGPZZhQRpQD/VBR 5IrmmXZNBIue3PRe4L1IX9z18/ZpXgHkcpGhSJsxKpMaZT+fLQk64vJVTgjjxmQImMUw Pa3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=6wS0ki92N6u9IiwfY7vGKrg8x6PBZLouUUMpfz5PbFI=; b=gFQegoJ8dxU1F1//A6M0WiEuiumGuBhMsPf10RRLajFLVxdp8wloe3xqh+qUSaNHmm SOgSvjO8sjcCWH+aiQ+Zjn9zVbww1okkmwRMiA0pGK4Kg1W3Z8AGBdPLnfFFsVP3r+pU fMJg53kTPh02x30Y2lNALWcjeJgqsMZeiIH8f7kwtvaRIoudaMLmucdp74YaLkk1lJ+k APwmhQG6wlhAlFxQsHOe/asImyR2FdQrrngH0uXstVPwQUkxyS2EyHOUDJpOHjvySZ2h ncYwIV/Z+GoSRU3Ajhw7hghfFFDDR+LQhRVV65rWTv1bxgpnhpejOpka1RvWY/F4jjd6 acyQ== X-Gm-Message-State: AO0yUKV2VrAJPixQijdESOqtlpCiUzpnDAmRpA7Oqb6SFiZ004gcU6BY LR/dtdqDHhTKolNthHqHCttqzRxNogMwiqUCGFKMOcUR9YY= X-Google-Smtp-Source: AK7set9AY2LdUe3LaR3jDCXAEOSGlVnGltYNClU533A50Bnqc7aodr0A8onYUhbbQOLBTb/DDKG1j0zOuq8jKVXpLm8= X-Received: by 2002:adf:fcc9:0:b0:2c7:156c:ae8d with SMTP id f9-20020adffcc9000000b002c7156cae8dmr1255944wrs.2.1677331055727; Sat, 25 Feb 2023 05:17:35 -0800 (PST) In-Reply-To: <83bklikogf.fsf@gnu.org> Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=dalanicolai@gmail.com; helo=mail-wr1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:303800 Archived-At: --000000000000bf69cf05f5861141 Content-Type: text/plain; charset="UTF-8" This is great! Indeed, it works perfectly now. I think using the margins is just much more elegant. Although, I might have read about this behavior somewhere, obviously, it was not clear to me that `erase-buffer` does not remove the overlays. Maybe a warning/reminder about this could be added in the 'erase-buffer' docstring? What do you think? I would be happy to create a patch for that (if desired). Anyway, thanks a lot again Eli, for having a look at it. Obviously, I really appreciate it. On Sat, 25 Feb 2023 at 11:51, Eli Zaretskii wrote: > > From: dalanicolai > > Date: Fri, 24 Feb 2023 21:53:35 +0100 > > Cc: emacs-devel@gnu.org > > > > B.t.w if someone want to have a look, I'll attach a smaller file here > where > > I have just removed about 200 pages of the book text data, so that it is > > the file is much smaller, but there is still enough date to clearly show > the > > 'undesired' behavior. > > > > So now, Emacs will not 'hang', but there will still be a clear > difference in time it > > takes to update the buffer (between when window margins are displayed, > > and when they are not). > > Your code overwhelms redisplay with an inconceivably huge number of > overlays that are left from the previous iteration. This one-line > change makes the code work reasonably fast: > > (defun baleen-update2 () > ;; (let ((query (minibuffer-contents))) > ;; (with-current-buffer (get-buffer-create "*baleen*") > ;; (erase-buffer) > ;; (baleen-render (baleen-filter test2 query))))) > (let* ((query (minibuffer-contents)) > (query-length (length query))) > (if (> (length previous-query) query-length) > (with-current-buffer (get-buffer-create "*baleen*") > (erase-buffer) > (baleen-render (cdr (alist-get query baleen-results nil nil > #'string=)))) > (let* ((parent-results (unless (< query-length 2) > (alist-get (substring query 0 -1) > baleen-results nil nil #'string=))) > (current-results (if parent-results > (baleen-filter parent-results query) > (unless (string-empty-p query) > (baleen-filter test2 query))))) > (when current-results > (with-current-buffer (get-buffer-create "*baleen*") > (remove-overlays) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< > (erase-buffer) > (baleen-render current-results)) > (cl-pushnew (cons query current-results) baleen-results :test > #'string= :key #'car)) > > (setq previous-query query))))) > --000000000000bf69cf05f5861141 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
This is great! Indeed, it works perfectly now.
<= div>I think using the margins is just much more elegant.

Although, I might have read about this behavior somewhere,
obviously, it was not clear to me that `erase-buffer` does not
r= emove the overlays. Maybe a warning/reminder about this could
=C2= =A0be added in the 'erase-buffer' docstring? What do you think?
I would be happy to create a patch for that (if desired).=

Anyway, thanks a lot again Eli, for having a = look at it.
Obviously, I really appreciate it.


On Sat, 25 Feb 2023 at 11:51, Eli Zaretskii <eliz@gnu.org> wrote:
> From: dalanicolai <dalanicolai@gmail.com>
> Date: Fri, 24 Feb 2023 21:53:35 +0100
> Cc: emacs-dev= el@gnu.org
>
> B.t.w if someone want to have a look, I'll attach a smaller file h= ere where
> I have just removed about 200 pages of the book text data, so that it = is
> the file is much smaller, but there is still enough date to clearly sh= ow the
> 'undesired' behavior.
>
> So now, Emacs will not 'hang', but there will still be a clear= difference in time it
> takes to update the buffer (between when window margins are displayed,=
> and when they are not).

Your code overwhelms redisplay with an inconceivably huge number of
overlays that are left from the previous iteration.=C2=A0 This one-line
change makes the code work reasonably fast:

(defun baleen-update2 ()
=C2=A0 ;; (let ((query (minibuffer-contents)))
=C2=A0 ;;=C2=A0 =C2=A0(with-current-buffer (get-buffer-create "*baleen= *")
=C2=A0 ;;=C2=A0 =C2=A0 =C2=A0(erase-buffer)
=C2=A0 ;;=C2=A0 =C2=A0 =C2=A0(baleen-render (baleen-filter test2 query)))))=
=C2=A0 (let* ((query (minibuffer-contents))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(query-length (length query)))
=C2=A0 =C2=A0 (if (> (length previous-query) query-length)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (with-current-buffer (get-buffer-create "*= baleen*")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (erase-buffer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (baleen-render (cdr (alist-get query bal= een-results nil nil #'string=3D))))
=C2=A0 =C2=A0 =C2=A0 (let* ((parent-results (unless (< query-length 2) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(alist-get (substring query 0 -1) bal= een-results nil nil #'string=3D)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(current-results (if parent= -results
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (baleen-filter parent-results= query)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (unless (string-empty-p query) (bale= en-filter test2 query)))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (when current-results
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (with-current-buffer (get-buffer-create = "*baleen*")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (remove-overlays) <<<<= ;<<<<<<<<<<<<<<<<<<&l= t;<<<<<<<<<<<<<<
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (erase-buffer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (baleen-render current-results))<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (cl-pushnew (cons query current-results)= baleen-results :test #'string=3D :key #'car))

=C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq previous-query query)))))
--000000000000bf69cf05f5861141--