unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: JD Smith <jdtsmith@gmail.com>
To: Stefan Kangas <stefankangas@gmail.com>,
	Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
Subject: Re: Temporarily select-window, without updating mode-line face and cursor fill?
Date: Wed, 5 May 2021 20:16:47 -0400	[thread overview]
Message-ID: <0E9544F6-15BD-409F-8D0E-73ACD1A0CA6C@gmail.com> (raw)
In-Reply-To: <CADwFkm=W88GAx226WYyKvub_W9esYVKWL1SBNUXJtSaKPVp_6A@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2129 bytes --]


> 
> Here's another one I threw together, tested here in src/keymap.c:
> 
> (defvar bench-run-times 10000)
> ...
> However, if I ramp up bench-run-times to 100000 I start seeing GC hits,
> and then nlinum--line-number-at-pos can be up to 10 times slower
> Instead…


I got some speedup for free because I’m always interested in the line number at (point-max), and that remains fixed until the buffer changes. But otherwise, for random jumps that span a large fraction of a file’s length, I found “most recent line” caching doesn’t help you too much, as you might expect.  But far more likely than jumping at random in a buffer is asking for many nearby line numbers in rapid succession (e.g. scrolling).  I simulated that by skipping say 3000±1500 characters ahead at a time.  For that access pattern, the speedup of “most recent” caching is tremendous, and increases linearly with position in a file.  

I should point out that in my testing, format-mode-line %l performs even at worst case 10x better than line-number-at-pos, but both of them scale together with position in the file; i.e. both are counting lines from the beginning of the file (but one is doing it in C).  When a file hasn’t changed, this is just tremendously inefficient.  It does seem to have some kind of very nearby caching built in, since taking small steps (like a couple characters) leads to freakish speed in the 10µs range.

To support more random access patterns, it may pay to cache more than just the “last line”.  E.g. if the distance from the closest last position is >20% of the (narrowed) buffer length, save another line on the cache (up to some fixed number of lines), in addition to the most recent.  Finding the nearest cached point wouldn’t be free, and a deeper cache might slow down sequential (scrolling) cached line calculation a bit, but a modest amount of spread might be worth it to improve performance in the more general case.  I’d personally favor `line-number-at-pos-cached' or perhaps a new optional CACHED argument, since there may be other caching strategies people have employed.

[-- Attachment #2: Type: text/html, Size: 7085 bytes --]

      parent reply	other threads:[~2021-05-06  0:16 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-01 18:46 Temporarily select-window, without updating mode-line face and cursor fill? JD Smith
2021-05-01 19:31 ` Eli Zaretskii
2021-05-01 20:32   ` JD Smith
2021-05-02  6:49     ` Eli Zaretskii
2021-05-03  2:15       ` JD Smith
2021-05-03  7:50         ` martin rudalics
2021-05-03 16:16           ` JD Smith
2021-05-03 17:32             ` martin rudalics
2021-05-02  7:40     ` martin rudalics
2021-05-03  2:23       ` JD Smith
2021-05-01 22:17   ` JD Smith
2021-05-02  6:55     ` Eli Zaretskii
2021-05-03  2:08       ` JD Smith
2021-05-03  2:25         ` Stefan Monnier
2021-05-03  2:49           ` JD Smith
2021-05-04 19:28           ` JD Smith
2021-05-04 19:40             ` Stefan Monnier
2021-05-05  0:49           ` Stefan Kangas
2021-05-05 11:54             ` Eli Zaretskii
2021-05-05 19:32               ` Stefan Kangas
2021-05-05 19:47                 ` Stefan Monnier
2021-05-06  0:16                 ` JD Smith [this message]

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0E9544F6-15BD-409F-8D0E-73ACD1A0CA6C@gmail.com \
    --to=jdtsmith@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=stefankangas@gmail.com \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).