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 07:40:42 +0300 Message-ID: <86bk1q1m0l.fsf@gnu.org> References: <54d1d667-55d0-41fc-9eec-38b3881d799b@orange.fr> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35351"; 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 06:43:53 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 1sfXlh-00098T-6T for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 18 Aug 2024 06:43:53 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sfXlG-0005cj-6A; Sun, 18 Aug 2024 00:43: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 1sfXlD-0005cT-EZ for bug-gnu-emacs@gnu.org; Sun, 18 Aug 2024 00:43:23 -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 1sfXlD-000710-2b for bug-gnu-emacs@gnu.org; Sun, 18 Aug 2024 00:43: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=9J9tRKdpKzbA4kRIUKfL2PBJEGPwsN+yOVkJNfkkDQQ=; b=V7mLzDc2BVQr/NclNsWhXJgru+AVpR4KeZuIKj3Q95r0gGOIldkGY3S2rD1Mqia8xt1hWe0/vFnW5FKDhdRFmhjGoHPudGnNg1fRk+j0icS+3crFSsMYqGB71DWaoClt6MIV6Fp2etQXyVdAhx4oHUuLQvtp9NqNLDWTqI4yEKylxxj2wKxVJq0JuwOIxH/7WqU1/1vOujxlHczDKrWSwo0lFCCVnLH0refdSsTzWR4SWAXtMgEpP3v85EfCHgXqxsSoyiYsHdD8/w+zLQ9wEBx1a8gR5sq71/CLyh7jRKfDoFuHMHUx1Ph6nkbqbbfetMMku8La+CXfkI22kUqWng==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sfXlq-00008L-GQ for bug-gnu-emacs@gnu.org; Sun, 18 Aug 2024 00:44: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 04:44: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.1723956226482 (code B ref 72689); Sun, 18 Aug 2024 04:44:02 +0000 Original-Received: (at 72689) by debbugs.gnu.org; 18 Aug 2024 04:43:46 +0000 Original-Received: from localhost ([127.0.0.1]:55212 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfXlZ-00007i-FQ for submit@debbugs.gnu.org; Sun, 18 Aug 2024 00:43:45 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:48816) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfXlX-00007U-CO for 72689@debbugs.gnu.org; Sun, 18 Aug 2024 00:43:44 -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 1sfXig-000540-Mm; Sun, 18 Aug 2024 00:40:46 -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=9J9tRKdpKzbA4kRIUKfL2PBJEGPwsN+yOVkJNfkkDQQ=; b=qBTbCaCuTlQL d3VvWm4vB+NFRlAgjslUusslrxa4LYcm+ptMJfk3IgL0lGwFt+lnDAnIwY//N4X1VIOVVVuyxgA3f J9PUUiL1tpA2wTlJ71FqpWID5qwC3OmWEBTbyMf1LV3aWjYheXuwsHeh9yuLTnl8+vBjhjn8OUTbJ 0vvhouxjkHYBuH6A9xRIZPrX91HKeOcJoj9aKMJ8Lv6x90nRzuSUw/p4emMBpVHG3P14bIY/q6YqL pkTXN7KalJ+bow/Fg2CsaNCAo1qyGUyBywUMzVnX6a1TdBy6XWDvXofCa6DkCWuDH+BvP58xmTggO m0Zn95cbH9aoxiDOg9dTAA==; In-Reply-To: <54d1d667-55d0-41fc-9eec-38b3881d799b@orange.fr> (bug-gnu-emacs@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:290290 Archived-At: > 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.