From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier 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 12:40:43 -0500 Message-ID: References: <83y4aclofm.fsf@gnu.org> <878s7z532u.fsf@gnus.org> <87y2fz3lpe.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37673"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 22763@debbugs.gnu.org, Keith David Bershatsky To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 07 18:41:27 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 1l8o3p-0009gL-Re for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 07 Feb 2021 18:41:26 +0100 Original-Received: from localhost ([::1]:42492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l8o3o-0002WW-Tb for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 07 Feb 2021 12:41:24 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46808) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l8o3S-0002IT-35 for bug-gnu-emacs@gnu.org; Sun, 07 Feb 2021 12:41:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37118) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l8o3R-0001Uh-S5 for bug-gnu-emacs@gnu.org; Sun, 07 Feb 2021 12:41:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l8o3R-0006vr-O5 for bug-gnu-emacs@gnu.org; Sun, 07 Feb 2021 12:41:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 07 Feb 2021 17:41: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.161271965826630 (code B ref 22763); Sun, 07 Feb 2021 17:41:01 +0000 Original-Received: (at 22763) by debbugs.gnu.org; 7 Feb 2021 17:40:58 +0000 Original-Received: from localhost ([127.0.0.1]:48664 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l8o3O-0006vS-J4 for submit@debbugs.gnu.org; Sun, 07 Feb 2021 12:40:58 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:25247) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l8o3M-0006vD-17 for 22763@debbugs.gnu.org; Sun, 07 Feb 2021 12:40:57 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 72CBF440126; Sun, 7 Feb 2021 12:40:50 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 02968440BBF; Sun, 7 Feb 2021 12:40:44 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1612719645; bh=Dv5g85dKVCuzKPR3kuKCO5JbgJCP0YrwL3UZmuOasbM=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=Q2PFM0PaLUqhrrxSHFcXIuXbdQQkzNPjL7+KXiZEsM50DAKrvFWdIng10iFYbDKAs 4gl7Hwh6xj+LcW8TbR8d5aDTDB5EFlB8rkUdwmDhF9r8zjisIQYha73hApTVz/Md56 hkdavEnQXMKAEbEPIkqNG/TJngvOd5EATF1VmXzuWcolsw9n8NFHKAzyr/6R9U0ioH MxfmmBP+Rw3QYipDM4NilRi0GCb18uwPyOalqivB+xCIqB3oX6W0fcM9Pf8UKR6DM4 AjL/eZ0s4R9hXVFm0Y5sQDNiVgI1DFkvoqc/G8TVWvNbCKR1jt8IJaihbK9nXZRpnO nEnMK8IHy6Ilw== Original-Received: from alfajor (unknown [216.154.41.47]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 91FD9120056; Sun, 7 Feb 2021 12:40:44 -0500 (EST) In-Reply-To: <87y2fz3lpe.fsf@gnus.org> (Lars Ingebrigtsen's message of "Sun, 07 Feb 2021 17:07:57 +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:199522 Archived-At: > This takes 2.8s in Emacs 27 and 0.3s after the change: > > (with-temp-buffer > (insert-file-contents "~/src/emacs/trunk/src/ChangeLog.11") > (benchmark-run 1000 > (line-number-at-pos (point-max)))) > > So that's nice. `line-number-at-pos' is used all over Emacs, but > probably not in a loop a lot, so it probably doesn't make much > difference, though. Why is it faster? Is it still always =CE=98(N) just with a smaller constant (if so, what makes the constant smaller), or does it benefit from some kind of caching (which I fail to see in the code) such that it's O(N) sometimes but much faster other times (and if so, what are the cases that are sped up)? Stefan