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 00:03:22 +0200 Message-ID: <54d1d667-55d0-41fc-9eec-38b3881d799b@orange.fr> Reply-To: David Ponce Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------uPXkRH5auj0C9sXHDP0kdNMG" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13351"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird To: 72689@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Aug 18 00:04:43 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 1sfRXO-0003Nq-MI for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 18 Aug 2024 00:04:42 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sfRX7-0000si-0E; Sat, 17 Aug 2024 18:04:25 -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 1sfRX5-0000sG-20 for bug-gnu-emacs@gnu.org; Sat, 17 Aug 2024 18:04: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 1sfRX4-0003Pr-Ox for bug-gnu-emacs@gnu.org; Sat, 17 Aug 2024 18:04:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=From:MIME-Version:Date:To:Subject; bh=xHiS+w4y8rC0eBjQuK4nJa9QBB1YnZlG/pvDMvonVPM=; b=SeTtgF2HTL9qfNm1DlyeGf+128eGo+vpGfARUofliAtHfyauEISkh6XfTkKW5XJg1R4jJMD3D+kLFkyeXgEYpAQm4d/d4wGnWU6uVnJBId2d2R95L6FD9ALMyeUwbzKOVt8fzf9emdXSiF5pZMB+H7nVQnFyu/ZVAZWVRR5P1yqsyJRJbgXejNvsQ03nWO4zB2Y6EJq4Qp7trgDJItruhMrb94bLAN1y3ukPv5RJhQBllKefOFxxmQMlo+XSG+k4RjA2g/6EtIXdycaEZA9tPoYIibEaLXK+1XSsSoyb0uOQqcv9pIPfOw5cODPKJ+6C321YHTMyaZiN5vRjDIN1WA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sfRXh-0006Mj-RX for bug-gnu-emacs@gnu.org; Sat, 17 Aug 2024 18:05:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: David Ponce Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 17 Aug 2024 22:05:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 72689 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.172393226224410 (code B ref -1); Sat, 17 Aug 2024 22:05:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 17 Aug 2024 22:04:22 +0000 Original-Received: from localhost ([127.0.0.1]:55040 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfRX3-0006Ld-8x for submit@debbugs.gnu.org; Sat, 17 Aug 2024 18:04:21 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:40506) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfRX0-0006LU-4k for submit@debbugs.gnu.org; Sat, 17 Aug 2024 18:04:19 -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 1sfRWL-0000oR-Sz for bug-gnu-emacs@gnu.org; Sat, 17 Aug 2024 18:03:38 -0400 Original-Received: from smtp-72.smtpout.orange.fr ([80.12.242.72] helo=msa.smtpout.orange.fr) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sfRWH-0003MD-0c for bug-gnu-emacs@gnu.org; Sat, 17 Aug 2024 18:03:36 -0400 Original-Received: from [192.168.1.21] ([2.7.225.247]) by smtp.orange.fr with ESMTPA id fRW6slCzTQRySfRW6sTElJ; Sun, 18 Aug 2024 00:03:24 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=orange.fr; s=t20230301; t=1723932204; bh=xHiS+w4y8rC0eBjQuK4nJa9QBB1YnZlG/pvDMvonVPM=; h=Message-ID:Date:MIME-Version:To:From:Subject; b=H5UqWgnq594rEnSDi2em3Mm3Ysqo4S8YxDWoaObEWYvZk0Yk3JILzN37SZmFH48Tb cwapRKPdVcdhczNzWpPPrieL8Yf1pdSQmWm2kwBQPZzFYwVNB0WsF/Lis/lR1ytSlz Pn8G6oqftiumFjM0cwSW9+aw3aIvzJcTS0kJpLj12l/IICF0TmizRcL4Z4arc/S2s5 Ijx634RWSZF52IC/ZD6MddgyRcl3KLPqRX6t6e20hICtrma4ggmf/LlsRsdq+FvMPc Vs/FLf+57uxPq3Y/joR374r/EFd3Ko4Y5WZwttp57klFTPhI1ue8Od7McRUmPwNN1n x05xiz59TmYLQ== X-ME-Helo: [192.168.1.21] X-ME-Auth: ZGFfdmlkQHdhbmFkb28uZnI= X-ME-Date: Sun, 18 Aug 2024 00:03:24 +0200 X-ME-IP: 2.7.225.247 Content-Language: fr, en-US Received-SPF: pass client-ip=80.12.242.72; envelope-from=da_vid@orange.fr; helo=msa.smtpout.orange.fr X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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:290283 Archived-At: This is a multi-part message in MIME format. --------------uPXkRH5auj0C9sXHDP0kdNMG Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hello, 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 In GNU Emacs 31.0.50 (build 6, x86_64-pc-linux-gnu, GTK+ Version 3.24.43, cairo version 1.18.0) of 2024-08-17 Repository revision: 40eecd594ac60f38b6729fd9cf3474a8b9d133b9 Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.12014000 System Description: Fedora Linux 40 (KDE Plasma) Configured using: 'configure --with-x-toolkit=gtk3 --with-cairo-xcb --with-native-compilation=no PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig' Configured features: ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB Important settings: value of $LC_TIME: fr_FR.utf8 value of $LANG: fr_FR.UTF-8 locale-coding-system: utf-8-unix --------------uPXkRH5auj0C9sXHDP0kdNMG Content-Type: text/x-patch; charset=UTF-8; name="improve-string-pixel-width-V00.patch" Content-Disposition: attachment; filename="improve-string-pixel-width-V00.patch" Content-Transfer-Encoding: base64 MjAyNC0wOC0xNyAgRGF2aWQgUG9uY2UgIDxkYV92aWRAb3JhbmdlLmZyPgoKCVR3ZWFrIHRo ZSBpbXBsZW1lbnRhdGlvbiBvZiBzdHJpbmctcGl4ZWwtd2lkdGggdG8gcnVuIGZhc3RlciBh bmQKCXVzZSBsZXNzIG1lbW9yeS4KCgkqIHN1YnIteC5lbCAoc3RyaW5nLS1waXhlbC13aWR0 aC1idWZmZXIpOiBOZXcgdmFyaWFibGUgYW5kIGZ1bmN0aW9uLgoJKHN0cmluZy0tcGl4ZWwt d2lkdGgpOiBVc2UgaXQuICBQcmVmZXIgYHJlbW92ZS10ZXh0LXByb3BlcnRpZXMnIHRvCglg cHJvcGVydGl6ZScgdG8gYXZvaWQgY3JlYXRpbmcgYSBuZXcgc3RyaW5nIG9uIGVhY2ggY2Fs bC4KCgpkaWZmIC0tZ2l0IGEvbGlzcC9lbWFjcy1saXNwL3N1YnIteC5lbCBiL2xpc3AvZW1h Y3MtbGlzcC9zdWJyLXguZWwKaW5kZXggMDU4YzA2YmM1ZjYuLjFmNTY0ZmE1NjI4IDEwMDY0 NAotLS0gYS9saXNwL2VtYWNzLWxpc3Avc3Vici14LmVsCisrKyBiL2xpc3AvZW1hY3MtbGlz cC9zdWJyLXguZWwKQEAgLTMzNiw2ICszMzYsMjMgQEAgbmFtZWQtbGV0CiAgICAgICAoY2wt bGFiZWxzICgoLG5hbWUgLGZhcmdzIC4gLGJvZHkpKSAjJyxuYW1lKQogICAgICAgLiAsYWFy Z3MpKSkKIAorKGRlZnZhciBzdHJpbmctLXBpeGVsLXdpZHRoLWJ1ZmZlciBuaWwpCisKKyhk ZWZzdWJzdCBzdHJpbmctLXBpeGVsLXdpZHRoLWJ1ZmZlciAo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ogICAgICAgKGlmIGJ1ZmZlcgogICAgICAgICAgIChzZXRxLWxvY2FsIGZhY2UtcmVtYXBw aW5nLWFsaXN0CiAgICAgICAgICAgICAgICAgICAgICAgKHdpdGgtY3VycmVudC1idWZmZXIg YnVmZmVyCiAgICAgICAgICAgICAgICAgICAgICAgICBmYWNlLXJlbWFwcGluZy1hbGlzdCkp CiAgICAgICAgIChraWxsLWxvY2FsLXZhcmlhYmxlICdmYWNlLXJlbWFwcGluZy1hbGlzdCkp Ci0gICAgICAoaW5zZXJ0IChwcm9wZXJ0aXplIHN0cmluZyAnbGluZS1wcmVmaXggbmlsICd3 cmFwLXByZWZpeCBuaWwpKQorICAgICAgKGluc2VydCBzdHJpbmcpCisgICAgICA7OyBQcmVm ZXIgYHJlbW92ZS10ZXh0LXByb3BlcnRpZXMnIHRvIGBwcm9wZXJ0aXplJyB0byBhdm9pZAor ICAgICAgOzsgY3JlYXRpbmcgYSBuZXcgc3RyaW5nIG9uIGVhY2ggY2FsbC4KKyAgICAgIChy ZW1vdmUtdGV4dC1wcm9wZXJ0aWVzCisgICAgICAgKHBvaW50LW1pbikgKHBvaW50LW1heCkg JyhsaW5lLXByZWZpeCBuaWwgd3JhcC1wcmVmaXggbmlsKSkKICAgICAgIChjYXIgKGJ1ZmZl ci10ZXh0LXBpeGVsLXNpemUgbmlsIG5pbCB0KSkpKSkKIAogOzs7IyMjYXV0b2xvYWQK --------------uPXkRH5auj0C9sXHDP0kdNMG--