From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.devel Subject: Re: Temporarily select-window, without updating mode-line face and cursor fill? Date: Wed, 5 May 2021 14:32:27 -0500 Message-ID: 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 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20293"; mail-complaints-to="usenet@ciao.gmane.io" Cc: monnier@iro.umontreal.ca, jdtsmith@gmail.com, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed May 05 21:39:11 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 1leNMU-00058g-RM for ged-emacs-devel@m.gmane-mx.org; Wed, 05 May 2021 21:39:10 +0200 Original-Received: from localhost ([::1]:51042 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1leNMT-0005a9-TS for ged-emacs-devel@m.gmane-mx.org; Wed, 05 May 2021 15:39:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46444) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leNG4-0000xs-ME for emacs-devel@gnu.org; Wed, 05 May 2021 15:32:32 -0400 Original-Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]:44897) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1leNG2-0004K0-6b; Wed, 05 May 2021 15:32:32 -0400 Original-Received: by mail-pl1-x635.google.com with SMTP id b3so1658313plg.11; Wed, 05 May 2021 12:32:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:in-reply-to:references:mime-version:date:message-id:subject:to :cc; bh=VAI8P6IIp3YRxfLFwi5LCtUDe4GPaodq4bwTDXOowS8=; b=A5fkg+3IS/GDBWaW1IVfxXFs+TORLuvaHNzRoGZu54eB7F4OXNqHvR147tlXyAAQfW lJJgmBJnqwS7+YKSvLbl5qJsiXH9radEC1778yX/xshlRcSK7cCsaicTQz/ZyYw9wofp kwVR4dnUgoUzjYR6xGV4dazM7j/oXF5xCWqCVa+pwH4djd/t536HnuYCCwKpTw+QlpQC xYBDF901YXVrDDsDo1apXJnsVb6vxOnw/VC459cwd68w00NZHqRX8UBqfOj1Op84XC/4 yF5AifiZosRNwc0iuKgwHeLI1og5Bx6s1n8gWnh4C8N4IPchw1jmgkfbAadW1cNn/XwI 3PRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:in-reply-to:references:mime-version:date :message-id:subject:to:cc; bh=VAI8P6IIp3YRxfLFwi5LCtUDe4GPaodq4bwTDXOowS8=; b=FKyG59GZuyxjgC45ZaU7fjlAO+LEw4Jnzc69DHf2jrGxt9EJ50k+tnwIcwXTfsFZMc LZLhAJ+FGxGieJqNcjNrkwq0VTbZrxYl+YywML8FTA1i3b84+VT5aBsUJkZtHkzd+At3 MGrlBrDz00YXDYtM64+RgEoOhIVRCsVWZu9eb/u8hPYpwo7EpAtVuPSFZ6LL5XX3iKy3 PCn1fPJnPWuldwlb+yHjxiraRfU1AUtW/TRwvXheFynZ4YLewgEL5+GgZ3SLiHqxE1H6 BKnOg5G48ZMI3apgoEEB7bn915BDIsabK9exSGasLxyYb7Oeq4+5h2iP07zIUZlGEpQQ ihTQ== X-Gm-Message-State: AOAM533iZyGladAYO3gLhD+VXlGu5BurIF16K5m6cb3aVGeOKmCO0xOY ZKk5fvssYpDCjrPP7UlXR4ULUibLi4f75piAOAbfDnT7 X-Google-Smtp-Source: ABdhPJz42ThihgARfBZzW91meZ+sDlSmJuaX1f2A8FZVMNda8ouGk2m/wM+c3vBflFrzzL/rNIUuk8I/N+66/eHSFx8= X-Received: by 2002:a17:90a:b38a:: with SMTP id e10mr169673pjr.175.1620243148223; Wed, 05 May 2021 12:32:28 -0700 (PDT) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Wed, 5 May 2021 14:32:27 -0500 In-Reply-To: <83y2ct2y79.fsf@gnu.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=stefankangas@gmail.com; helo=mail-pl1-x635.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, 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:268924 Archived-At: Eli Zaretskii writes: >> > We really should simply speed up `line-number-at-pos`. >> > It shouldn't be hard. See below what I do in nlinum.el. >> >> Interesting, it seems much faster at least in this simplistic test: >> >> (benchmark-run 100000 (line-number-at-pos)) >> => (5.868677411999999 0 0.0) >> >> (benchmark-run 100000 (line-number-at-pos)) >> => (0.9772498589999999 1 0.5954873589998897) > > Doesn't this measure the line number of the same position? If so, > that's about as favorable benchmark for caching as possible, no? Yup. Here's another one I threw together, tested here in src/keymap.c: (defvar bench-run-times 10000) (defun line-number-at-pos-benchmark (lines) (let (results) (dolist (fun '(line-number-at-pos nlinum--line-number-at-pos)) (goto-char (/ (point-max) 2)) (save-excursion (push (cons fun (cons lines (benchmark-run bench-run-times (let ((n (- (random (/ lines 2)) (random (/ lines 2))))) (forward-line n)) (funcall fun)))) results))) results)) (defun run-bench (from to inc) (with-current-buffer (get-buffer-create "*Bench-Results*") (erase-buffer)) (mapc (lambda (res) ;; ((nlinum--line-number-at-pos 0 0.93488997 0 0.0) ;; (line-number-at-pos 0 1.0096957629999999 0 0.0)) (let ((a (car res)) (b (cadr res))) (with-current-buffer (get-buffer-create "*Bench-Results*") (insert (format (concat "%3s: " "%s %6.3f %2d %6.3f | " "%s %6.3f %2d %6.3f [%5.2f %% faster]\n") (cadr b) (car a) (caddr a) (cadddr a) (car (cddddr a)) (car b) (caddr b) (cadddr b) (car (cddddr b)) (* (- 1.0 (/ (caddr a) (caddr b))) 100)))))) (mapcar #'line-number-at-pos-benchmark (number-sequence from to inc))) (pop-to-buffer "*Bench-Results*")) Now, (run-bench 0 100 5) gives me: 0: nlinum--line-number-at-pos 0.963 0 0.000 | line-number-at-pos 1.107 0 0.000 [13.04 % faster] 5: nlinum--line-number-at-pos 0.027 0 0.000 | line-number-at-pos 0.118 0 0.000 [77.13 % faster] 10: nlinum--line-number-at-pos 0.030 0 0.000 | line-number-at-pos 0.174 0 0.000 [82.56 % faster] 15: nlinum--line-number-at-pos 0.031 0 0.000 | line-number-at-pos 0.170 0 0.000 [81.80 % faster] 20: nlinum--line-number-at-pos 0.033 0 0.000 | line-number-at-pos 0.209 0 0.000 [84.26 % faster] 25: nlinum--line-number-at-pos 0.035 0 0.000 | line-number-at-pos 0.170 0 0.000 [79.45 % faster] 30: nlinum--line-number-at-pos 0.037 0 0.000 | line-number-at-pos 0.109 0 0.000 [65.96 % faster] 35: nlinum--line-number-at-pos 0.039 0 0.000 | line-number-at-pos 0.094 0 0.000 [58.57 % faster] 40: nlinum--line-number-at-pos 0.040 0 0.000 | line-number-at-pos 0.077 0 0.000 [48.01 % faster] 45: nlinum--line-number-at-pos 0.044 0 0.000 | line-number-at-pos 0.117 0 0.000 [62.09 % faster] 50: nlinum--line-number-at-pos 0.044 0 0.000 | line-number-at-pos 0.181 0 0.000 [75.77 % faster] 55: nlinum--line-number-at-pos 0.046 0 0.000 | line-number-at-pos 0.106 0 0.000 [57.01 % faster] 60: nlinum--line-number-at-pos 0.048 0 0.000 | line-number-at-pos 0.085 0 0.000 [43.54 % faster] 65: nlinum--line-number-at-pos 0.052 0 0.000 | line-number-at-pos 0.114 0 0.000 [54.87 % faster] 70: nlinum--line-number-at-pos 0.052 0 0.000 | line-number-at-pos 0.115 0 0.000 [54.48 % faster] 75: nlinum--line-number-at-pos 0.055 0 0.000 | line-number-at-pos 0.208 0 0.000 [73.71 % faster] 80: nlinum--line-number-at-pos 0.058 0 0.000 | line-number-at-pos 0.185 0 0.000 [68.89 % faster] 85: nlinum--line-number-at-pos 0.059 0 0.000 | line-number-at-pos 0.157 0 0.000 [62.57 % faster] 90: nlinum--line-number-at-pos 0.061 0 0.000 | line-number-at-pos 0.185 0 0.000 [67.22 % faster] 95: nlinum--line-number-at-pos 0.063 0 0.000 | line-number-at-pos 0.102 0 0.000 [38.34 % faster] 100: nlinum--line-number-at-pos 0.064 0 0.000 | line-number-at-pos 0.729 1 0.597 [91.24 % faster] 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...