From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#35675: 27.0.50; Is line-number-at-pos unnecessarily slow? Date: Sat, 11 May 2019 09:03:14 +0300 Message-ID: <83tve1edel.fsf@gnu.org> References: <87zhnuuj0y.fsf@gmail.com> Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="25460"; mail-complaints-to="usenet@blaine.gmane.org" Cc: 35675@debbugs.gnu.org To: Alex Branham Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat May 11 08:04:10 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hPL7C-0006SU-Kd for geb-bug-gnu-emacs@m.gmane.org; Sat, 11 May 2019 08:04:10 +0200 Original-Received: from localhost ([127.0.0.1]:54787 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hPL7B-0007G1-BG for geb-bug-gnu-emacs@m.gmane.org; Sat, 11 May 2019 02:04:09 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:56310) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hPL75-0007Fe-UL for bug-gnu-emacs@gnu.org; Sat, 11 May 2019 02:04:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hPL75-0000wy-0x for bug-gnu-emacs@gnu.org; Sat, 11 May 2019 02:04:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54411) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hPL74-0000wb-U0 for bug-gnu-emacs@gnu.org; Sat, 11 May 2019 02:04:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hPL74-00021x-Gh for bug-gnu-emacs@gnu.org; Sat, 11 May 2019 02:04:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 11 May 2019 06:04:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35675 X-GNU-PR-Package: emacs Original-Received: via spool by 35675-submit@debbugs.gnu.org id=B35675.15575546167768 (code B ref 35675); Sat, 11 May 2019 06:04:02 +0000 Original-Received: (at 35675) by debbugs.gnu.org; 11 May 2019 06:03:36 +0000 Original-Received: from localhost ([127.0.0.1]:39721 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hPL6c-00021C-Vu for submit@debbugs.gnu.org; Sat, 11 May 2019 02:03:35 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:41822) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hPL6a-00020z-Vl for 35675@debbugs.gnu.org; Sat, 11 May 2019 02:03:33 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:35445) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hPL6U-0000V6-JS; Sat, 11 May 2019 02:03:26 -0400 Original-Received: from [176.228.60.248] (port=3223 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hPL6N-0003UX-VS; Sat, 11 May 2019 02:03:21 -0400 In-reply-to: <87zhnuuj0y.fsf@gmail.com> (message from Alex Branham on Fri, 10 May 2019 15:55:09 -0500) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:159067 Archived-At: > From: Alex Branham > Date: Fri, 10 May 2019 15:55:09 -0500 > > I ran into a bottleneck at line-number-at-pos in ESS's indentation > engine. line-number-at-pos basically regex searches forward for \n's and > counts them up. This can be slow in a large buffer. It looks like > someone else has ran into this issue as well.[1] > > With the advent of display-line-numbers-mode, I imagine there's a C > implementation of line-number-at-pos. I imagine the C implementation is > faster. Does it make sense for line-number-at-pos to just use the C > implementation? The C implementation was always there: it's what's behind the Lnn display in the mode line. display-line-numbers-mode just reuses that fir its purposes, but basically invents nothing new in that department. The usual wisdom regarding line-number-at-pos is to use count-lines instead, counting the number of lines since some previous line whose number is recorded. (By contrast, line-number-at-pos always starts from BOB.) For example, you could always have the line number of the first line in the window in some variable, and recompute it only when that line goes off the window. If this strategy somehow doesn't work in your case, please describe that use case in more detail, as IME it is very rare (read: non-existent). Using the C implementation we have from Lisp might not be as straight-forward as you'd think, because it caches various values in the window object, and relies on them being up-to-date. Code that runs during redisplay can rely on some assumption that Lisp cannot. One obvious difficulty is that you may need your Lisp program to count line in a buffer that isn't displayed in any window. Therefore, my suggestion is to get back to the drawing board and analyze your use case. I'd be very surprised if a solution simpler than just counting all the lines from BOB will not present itself.