From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#22763: 25.1.50; Feature Request -- A faster method to obtain line number at position. Date: Sun, 07 Feb 2021 21:42:33 +0200 Message-ID: <834kinmzpy.fsf@gnu.org> References: <83y4aclofm.fsf@gnu.org> <878s7z532u.fsf@gnus.org> <87y2fz3lpe.fsf@gnus.org> <87h7mn22ls.fsf@gnus.org> <83eehrn408.fsf@gnu.org> <87y2fzzqxb.fsf@gnus.org> <87tuqnzqh2.fsf@gnus.org> <83blcvn1ku.fsf@gnu.org> <87czxbznly.fsf@gnus.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3809"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 22763@debbugs.gnu.org, esq@lawlist.com, monnier@iro.umontreal.ca To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 07 20:43:09 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1l8pxd-0000vI-7v for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 07 Feb 2021 20:43:09 +0100 Original-Received: from localhost ([::1]:51636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l8pxc-0006g5-Ai for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 07 Feb 2021 14:43:08 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l8pxW-0006fm-6C for bug-gnu-emacs@gnu.org; Sun, 07 Feb 2021 14:43:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37314) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l8pxV-0005qt-VO for bug-gnu-emacs@gnu.org; Sun, 07 Feb 2021 14:43:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l8pxV-0001X2-QJ for bug-gnu-emacs@gnu.org; Sun, 07 Feb 2021 14:43:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 07 Feb 2021 19:43:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22763 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: fixed Original-Received: via spool by 22763-submit@debbugs.gnu.org id=B22763.16127269565856 (code B ref 22763); Sun, 07 Feb 2021 19:43:01 +0000 Original-Received: (at 22763) by debbugs.gnu.org; 7 Feb 2021 19:42:36 +0000 Original-Received: from localhost ([127.0.0.1]:48860 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l8px5-0001WN-Ig for submit@debbugs.gnu.org; Sun, 07 Feb 2021 14:42:36 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:51450) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l8px0-0001W7-Mu for 22763@debbugs.gnu.org; Sun, 07 Feb 2021 14:42:34 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:36340) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l8pwu-0005bl-Uw; Sun, 07 Feb 2021 14:42:24 -0500 Original-Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:4488 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1l8pwu-0006OS-9B; Sun, 07 Feb 2021 14:42:24 -0500 In-Reply-To: <87czxbznly.fsf@gnus.org> (message from Lars Ingebrigtsen on Sun, 07 Feb 2021 20:25:45 +0100) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:199551 Archived-At: > From: Lars Ingebrigtsen > Cc: 22763@debbugs.gnu.org, esq@lawlist.com, monnier@iro.umontreal.ca > Date: Sun, 07 Feb 2021 20:25:45 +0100 > > (with-temp-buffer > (dotimes (_ 1000) > (insert-file-contents "~/src/emacs/trunk/src/ChangeLog.11") > (goto-char (point-max))) > (benchmark-run 1 > (dotimes (i 100) > (goto-char (* (/ (buffer-size) 100) i)) > (line-number-at-pos (point))))) > > (Adjusted down to 100, because it takes too long.) Let's see... > > Yup, still 10x faster. This one traverses each 1/100th region of the file just once, no? > OK, I've now bumped the benchmark-run to 10 (and decreased the buffer > size by a factor of 10)... let's see... The new version takes exactly > the same amount of time, of course... > > And so does the old one. Well, it's 10% faster in this? 10% or 10-fold? > (with-temp-buffer > (dotimes (_ 100) > (insert-file-contents "~/src/emacs/trunk/src/ChangeLog.11") > (goto-char (point-max))) > (benchmark-run 10 > (dotimes (i 100) > (goto-char (* (/ (buffer-size) 100) i)) > (line-number-at-pos (point))))) > > Hm. I guess this doesn't update the newline cache in any useful way? Why not? It should. > > But in general, the raw speed of memchr is very hard to beat, > > especially given that using the cache requires calls to CHAR_TO_BYTE > > and BYTE_TO_CHAR, which can be expensive. > > So ... it's using the cache is only faster when we have monumentally > long lines, since memchr is so fast? Yes. > And in buffers with lines with normal line lengths, it's 10x slower? In my benchmarks some years ago it was about twice slower, not 10 times.