From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: David Ponce via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#72689: 31.0.50; Proposal to improve string-pixel-width Date: Sun, 18 Aug 2024 08:05:04 +0200 Message-ID: References: <54d1d667-55d0-41fc-9eec-38b3881d799b@orange.fr> <86bk1q1m0l.fsf@gnu.org> Reply-To: David Ponce Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20019"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: 72689@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Aug 18 08:05:47 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 1sfZ2x-00052o-4v for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 18 Aug 2024 08:05:47 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sfZ2b-0007aw-Ux; Sun, 18 Aug 2024 02:05:26 -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 1sfZ2Z-0007ai-TH for bug-gnu-emacs@gnu.org; Sun, 18 Aug 2024 02:05:25 -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 1sfZ2Z-0008BO-Kj for bug-gnu-emacs@gnu.org; Sun, 18 Aug 2024 02:05:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=In-Reply-To:From:References:MIME-Version:Date:To:Subject; bh=w3sZPmrcjZQnmES2mhTCE4kHV0nK9V3QPOM511Vg1SA=; b=mMygAJkUtQTF4Q8gcJqNM1WFkxLwYHE2GwZ9SkEk2mXdba7WzzEVTLAYcq6SN9JgoDg/bbUtwc0nHhwUZqH8/Ex8OrsoOuYxv2TspRmw7lakS7HJ5G+oTmZPqf3Smu3hO4DR+s6LiOk0pb3chEb8om0j7khFMoK+Sxoq5y5fV+lcJf3olG1125YNqqbXl/mtQhwVylEiDLfCkAXYydShdsMz67ycO3suSEQjBpoVXBRFZdwp0UOdIzE9Li2zXxMYkLDJ+tYUTY2k1PgPqE3okEeLRRNvvsPvyHsV5/Ak6W3HyW/ozK77TV6YGIXqT6fATn53Hb9EiLu27+E1LL/5eQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sfZ3C-0002tK-FZ for bug-gnu-emacs@gnu.org; Sun, 18 Aug 2024 02:06:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: David Ponce Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 18 Aug 2024 06:06: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.172396115211097 (code B ref 72689); Sun, 18 Aug 2024 06:06:02 +0000 Original-Received: (at 72689) by debbugs.gnu.org; 18 Aug 2024 06:05:52 +0000 Original-Received: from localhost ([127.0.0.1]:55311 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfZ32-0002sv-4N for submit@debbugs.gnu.org; Sun, 18 Aug 2024 02:05:52 -0400 Original-Received: from smtp-81.smtpout.orange.fr ([80.12.242.81]:63810 helo=msa.smtpout.orange.fr) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfZ2z-0002sl-4V for 72689@debbugs.gnu.org; Sun, 18 Aug 2024 02:05:50 -0400 Original-Received: from [192.168.1.21] ([2.7.225.247]) by smtp.orange.fr with ESMTPA id fZ2HswoSpu3XKfZ2Hse7Zb; Sun, 18 Aug 2024 08:05:07 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=orange.fr; s=t20230301; t=1723961107; bh=w3sZPmrcjZQnmES2mhTCE4kHV0nK9V3QPOM511Vg1SA=; h=Message-ID:Date:MIME-Version:Subject:To:From; b=MRbr9NuMLcdUQDvdVIQfy6Dj0m4NX1SN4v9c1WFPapJn6kX3Lk37xbNTh7mBeK9jV na5oW+CQbdU7KLpBk/q1ho2wTOsRhAcO4uQTOdOEZLjvG8yI1zhX+xWc24mVprmFm8 9/etUiSRxGaou50Ryni9wB7EPpQ6UhoN6oUHKuAa8iuIH2kGviVQhN1VVD3fLZvQaJ xKmFOt7/EUSlPwCI4sX3I8keRr+qvUhhwtp59T/KJ0HfeuBWFzCmw/5tIyzHb1eTV9 WHKmnTDBeI3RQ/qRR/5mn3YqEbhe8S6t34YbO7fgQs0aFA55COZAXUxkNV9Rc4fEAX zPbZkHtR3hP9A== X-ME-Helo: [192.168.1.21] X-ME-Auth: ZGFfdmlkQHdhbmFkb28uZnI= X-ME-Date: Sun, 18 Aug 2024 08:05:07 +0200 X-ME-IP: 2.7.225.247 Content-Language: fr, en-US In-Reply-To: <86bk1q1m0l.fsf@gnu.org> 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:290293 Archived-At: 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? 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?