From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: JD Smith Newsgroups: gmane.emacs.devel Subject: Re: Temporarily select-window, without updating mode-line face and cursor fill? Date: Wed, 5 May 2021 20:16:47 -0400 Message-ID: <0E9544F6-15BD-409F-8D0E-73ACD1A0CA6C@gmail.com> References: <56F746A2-B842-421E-8FBF-EA5E93EA26CE@gmail.com> <83pmya8d49.fsf@gnu.org> <904A57C8-C268-412F-815F-782017F47D5D@gmail.com> <83eeep8w0m.fsf@gnu.org> <81F181EB-D3C1-4619-B42A-1F49321EC544@gmail.com> <83y2ct2y79.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.80.0.2.43\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_1A26C679-9808-4A22-899D-D33F4194B8EB" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21042"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , emacs-devel@gnu.org To: Stefan Kangas , Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu May 06 02:18:19 2021 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 1leRic-0005LB-IR for ged-emacs-devel@m.gmane-mx.org; Thu, 06 May 2021 02:18:18 +0200 Original-Received: from localhost ([::1]:60346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1leRib-0001EV-LU for ged-emacs-devel@m.gmane-mx.org; Wed, 05 May 2021 20:18:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43152) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leRhG-0000fg-J4 for emacs-devel@gnu.org; Wed, 05 May 2021 20:16:54 -0400 Original-Received: from mail-qk1-x729.google.com ([2607:f8b0:4864:20::729]:35400) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1leRhE-0006ik-0u; Wed, 05 May 2021 20:16:54 -0400 Original-Received: by mail-qk1-x729.google.com with SMTP id x8so3452819qkl.2; Wed, 05 May 2021 17:16:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=ZSupqzlEqQS4OuJol5f+kMLRnNjvVd4uSfi3G+CuJtI=; b=MOK7Ov17dU8NYvX4RFHd1c7uRIs0DM4kcYvZl+G4hj0IzS2PrFmVbCKnpoAxGAyQ5O YY6tI8k6GVq044bKHWNHmxfWJbUBJg59wmlxvuKlUtBC1yTqyIGeURfgO34vIiwKK41N 8kcIvNGoAInrTV8OreKmCd61zPjkTDjWHQZ239KGn5zUG8Nf7em8Gh5gauJC+PNbWrXF 9Tm6mx2yRd1Wt1+NGW8OyNdJkN3CY0xnHqVaPNthGWoTop/4A9k5xu7NjhjlWJrZl9I/ PbSarGoIc5W87wwDdhJl+bmvUqF/h1Um1cKgYJeXW0vTADKFrryaW3PvuhoFsUZbG1TU dP8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=ZSupqzlEqQS4OuJol5f+kMLRnNjvVd4uSfi3G+CuJtI=; b=VVzgs3a7VyVFTFE2NMqHcS9/IufFDGKuB0ov8nZCWuADQkzys/35RIa22cN8of2hiT mCCl13a9icZCOO02qVeQYNJRw9AsfwV9crFlZNmFE+xKL6/Z//oUbUFXZDNlTdZ5FieK HatzXIbUeL6p5lq861+ugIOddeMsEr8OiUR8F/g6cY6qFt9YgJYiDp5+XMU4hj99nimG ufmvBxBzEYDOws1SGdZJTAdLNlbNxKVjnKBujq+az5GkgNxtPibzhKHnr1JCXzqfB/7x 9bP3wpwXSmJQ+0/YMqO39bTn9Oe+sVCihpiJyb6bTQxIK8mbomUuApQMkaHfbD5FXS1y L7Gw== X-Gm-Message-State: AOAM530mBJhmLO8IPGAL3BAn7eVEgqwDnhjhfxSi5aHQZVOrlbAPcbdl B53JJgkFCgJcVfDqBvtjq8I= X-Google-Smtp-Source: ABdhPJxjfE1LFr9tVdhfkJ667WSeCQV7miha8Ti04HmtBGWWdLIy4ZjfUnl+SCTsQW64SxKpQ1uk1w== X-Received: by 2002:a37:e11:: with SMTP id 17mr1419366qko.499.1620260209881; Wed, 05 May 2021 17:16:49 -0700 (PDT) Original-Received: from smtpclient.apple (cm-134-228-25-135.buckeyecom.net. [134.228.25.135]) by smtp.gmail.com with ESMTPSA id f5sm739763qkk.12.2021.05.05.17.16.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 May 2021 17:16:48 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3654.80.0.2.43) Received-SPF: pass client-ip=2607:f8b0:4864:20::729; envelope-from=jdtsmith@gmail.com; helo=mail-qk1-x729.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.23 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" Xref: news.gmane.io gmane.emacs.devel:268944 Archived-At: --Apple-Mail=_1A26C679-9808-4A22-899D-D33F4194B8EB Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 >=20 > Here's another one I threw together, tested here in src/keymap.c: >=20 > (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=E2=80=A6 I got some speedup for free because I=E2=80=99m 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=E2=80=99s length, I found =E2=80=9Cmost recent line=E2=80=9D = caching doesn=E2=80=99t 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=C2=B11500 characters ahead at a time. For that access = pattern, the speedup of =E2=80=9Cmost recent=E2=80=9D caching is = tremendous, and increases linearly with position in a file. =20 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=E2=80=99t 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=C2=B5s range. To support more random access patterns, it may pay to cache more than = just the =E2=80=9Clast line=E2=80=9D. 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=E2=80=99t 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=E2=80=99d personally favor `line-number-at-pos-cached' or perhaps a = new optional CACHED argument, since there may be other caching = strategies people have employed.= --Apple-Mail=_1A26C679-9808-4A22-899D-D33F4194B8EB Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

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=E2=80=A6

I got = some speedup for free because I=E2=80=99m 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=E2=80=99s length, I found =E2=80=9Cmost recent = line=E2=80=9D caching doesn=E2=80=99t 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=C2=B11500 characters ahead at a time. =  For that access pattern, the = speedup of =E2=80=9Cmost recent=E2=80=9D 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=E2=80=99t 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=C2=B5s range.

To support more random access patterns, = it may pay to cache more than just the =E2=80=9Clast line=E2=80=9D. =  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=E2=80=99t 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=E2=80=99d personally favor = `line-number-at-pos-cached' or perhaps a new optional CACHED argument, = since there may be other caching strategies people have = employed.
= --Apple-Mail=_1A26C679-9808-4A22-899D-D33F4194B8EB--