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#72689: 31.0.50; Proposal to improve string-pixel-width Date: Sun, 18 Aug 2024 12:15:14 +0300 Message-ID: <8634n219b1.fsf@gnu.org> References: <54d1d667-55d0-41fc-9eec-38b3881d799b@orange.fr> <86bk1q1m0l.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30983"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 72689@debbugs.gnu.org To: David Ponce Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Aug 18 11:16:56 2024 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 1sfc1w-0007sW-75 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 18 Aug 2024 11:16:56 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sfc1d-0006um-56; Sun, 18 Aug 2024 05:16:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sfc1P-0006tm-ES for bug-gnu-emacs@gnu.org; Sun, 18 Aug 2024 05:16:24 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sfc1O-0007e0-0C for bug-gnu-emacs@gnu.org; Sun, 18 Aug 2024 05:16:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=References:In-Reply-To:From:Date:To:Subject; bh=cWLn8Aaud0zYh2SsCfowHobyQ/XCxjWERydOn2E1pf8=; b=uynqAQvhEWBeUqyY5cW9N4DPauFQ98OwPyGknbl78etcSBTJ53toky91eSH5aczSxYLF/36uYwu5Nb5mkXKo8LbczwECQabxiT4nbTdh4FNtmPupCyyhUC1GdoZNTYZj8r1CThUP29xKaskBSl3bjZYEEulPi1RarT6MA/KNTNphUQnWge4k97twV1L0ICNtSwh7i3ovIeqpw1grYIbo7Cnbr+Hdce422xebWsJHNKXjHZkhyGjdLl+jAVKh4V0unwCaZrlGdIiqtHviip0Vk8JU0M3WvfSTjvMog/GMYl86TWlibbmogBg2lEc//2vX2Y0TZkgc9cWkNg3XJO08vA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sfc22-000811-1G for bug-gnu-emacs@gnu.org; Sun, 18 Aug 2024 05:17: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: Sun, 18 Aug 2024 09:17:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72689 X-GNU-PR-Package: emacs Original-Received: via spool by 72689-submit@debbugs.gnu.org id=B72689.172397257130721 (code B ref 72689); Sun, 18 Aug 2024 09:17:02 +0000 Original-Received: (at 72689) by debbugs.gnu.org; 18 Aug 2024 09:16:11 +0000 Original-Received: from localhost ([127.0.0.1]:55410 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfc1C-0007zQ-S1 for submit@debbugs.gnu.org; Sun, 18 Aug 2024 05:16:11 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:47540) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfc1A-0007z8-RX for 72689@debbugs.gnu.org; Sun, 18 Aug 2024 05:16:09 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sfc0O-0007aV-Rc; Sun, 18 Aug 2024 05:15:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=cWLn8Aaud0zYh2SsCfowHobyQ/XCxjWERydOn2E1pf8=; b=KGdNQVTlEhM7 y8i1e3+r0zz3w8/fjrqdP+fdNxjedE1d8aa+x8FVbC9l9NIEy18GfwJ2SwErFZ5sVsTwjshdr55PI 9h3UM1SMNSRRW1TEGz6YWMT44C/jg+S5eHrCPqD9eCfr3ciKHdoRPDKDO0hzUFxrGHdq6BHFP1ZyA jL3Ipsjk9ndtpTMoNxCPaIBf88oXiMKE1M4DNQUQjME9Sx/qY7WwB2s7b/82vkpPGCA5c6iIQGND6 NnE/nFqKLTf8fecOreYlA94/43AtKcBsMqftHZJPhTNpskiCTcV0oqbWN1pgl6uG/urkuccLEWWMc ztRsY/62Htwi8W0ya7KRLA==; In-Reply-To: (message from David Ponce on Sun, 18 Aug 2024 08:05:04 +0200) 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:290302 Archived-At: > Date: Sun, 18 Aug 2024 08:05:04 +0200 > Cc: 72689@debbugs.gnu.org > From: David Ponce > > On 18/08/2024 6:40 AM, Eli Zaretskii wrote: > >> Date: Sun, 18 Aug 2024 00:03:22 +0200 > >> From: David Ponce via "Bug reports for GNU Emacs, > >> the Swiss army knife of text editors" > >> > >> The function string-pixel-width is essential for calculating pixel > >> dimensions, especially for UI components. And in this context this > >> function can be called very often when the display is refreshed. > >> > >> I propose the attached patch to make string-pixel-width faster while > >> using less memory, as shown by the following results of a basic > >> benchmark run in emacs -Q to compare the current implementation and this > >> proposal: > >> > >> ;; Basic benchmark > >> (let* ((text1 (make-string 1000 ?x)) > >> (text2 (propertize text1 'line-prefix "XXXX "))) > >> (list > >> (string-pixel-width text1) > >> (string-pixel-width text2) > >> (progn (garbage-collect) > >> (benchmark-run 10000 (string-pixel-width text1))) > >> (progn (garbage-collect) > >> (benchmark-run 10000 (string-pixel-width text2))) > >> ;;(insert text "\n") > >> )) > >> > >> ;; Result with current implementation (4 run): > >> (12000 12000 (1.854707611 17 0.120106147) (1.884129905 17 0.12258791599999996)) > >> > >> (12000 12000 (1.846544798 17 0.12243524500000003) (1.8822177530000002 17 0.12349287399999997)) > >> > >> (12000 12000 (1.851244125 17 0.12162041699999998) (1.860517709 17 0.12352999599999998)) > >> > >> (12000 12000 (1.8542218929999998 17 0.12164553900000001) (1.856302462 17 0.122891689)) > >> > >> ;; Result with proposed implementation (4 run): > >> (12000 12000 (1.698974522 0 0.0) (1.727446 2 0.014782505999999973)) > >> > >> (12000 12000 (1.701800124 0 0.0) (1.728024111 2 0.014718454999999908)) > >> > >> (12000 12000 (1.6850850800000001 0 0.0) (1.732370238 2 0.014801913000000111)) > >> > >> (12000 12000 (1.7356390130000001 0 0.0) (1.7858915800000001 2 0.014816158000000135)) > >> > >> From my observations, the new implementation is around 8% faster, and > >> trigger less GC. When there is no line-prefix property to > >> remove, the new implementation doesn't trigger any GC after 10000 runs. > >> Otherwise, only 2 GC are triggered instead of 17. > >> > >> Maybe this proposal might be of interest, or at least provide some ideas > >> for improvement. > > > > Thanks. The idea SGTM, but I think the implementation needs to cater > > for the case where more than one execution thread performs this job > > "in parallel" (however improbable this could sound), so we need to be > > able to detect when this buffer is "busy". The simplest way is to use > > some boolean buffer-local variable, which will be set non-nil when the > > function starts using the buffer and reset to nil when the function is > > done with its job. > > Thanks. Your point about "parallelism" is quite relevant. However > I'm not sure I understand your suggestion to introduce a buffer-local > boolean variable. In particular, what to do when the buffer-local > flag is set when entering the function? Wait until the flag is > reset? Create another buffer? The latter, I think. > Perhaps for parallelism, using temporary buffers might be a better > approach? But I have no idea how much stress would be put on Emacs if > thousands of temporary buffers were created/freed during a session? > > Could you elaborate further? I think you understood the issue, and just creating a new buffer if the "normal" one is "taken" should be good enough. I don't expect this situation to be a frequent one, so creating too many buffers should not be a danger.