GNU logs - #77684, boring messages


Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#77684: [PATCH] ; * lisp/emacs-lisp/vtable.el (vtable--limit-string): Use binary search
Resent-From: Kristoffer Balintona <krisbalintona@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Thu, 10 Apr 2025 00:14:02 +0000
Resent-Message-ID: <handler.77684.B.17442440076955 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: report 77684
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: 77684 <at> debbugs.gnu.org
X-Debbugs-Original-To: bug-gnu-emacs@HIDDEN
Received: via spool by submit <at> debbugs.gnu.org id=B.17442440076955
          (code B ref -1); Thu, 10 Apr 2025 00:14:02 +0000
Received: (at submit) by debbugs.gnu.org; 10 Apr 2025 00:13:27 +0000
Received: from localhost ([127.0.0.1]:42760 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u2fXq-0001o6-VE
	for submit <at> debbugs.gnu.org; Wed, 09 Apr 2025 20:13:27 -0400
Received: from lists.gnu.org ([2001:470:142::17]:36426)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <krisbalintona@HIDDEN>)
 id 1u2fXn-0001nn-NM
 for submit <at> debbugs.gnu.org; Wed, 09 Apr 2025 20:13:24 -0400
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 <krisbalintona@HIDDEN>)
 id 1u2fXh-0005eM-LK
 for bug-gnu-emacs@HIDDEN; Wed, 09 Apr 2025 20:13:17 -0400
Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <krisbalintona@HIDDEN>)
 id 1u2fXf-0004Gk-Gu
 for bug-gnu-emacs@HIDDEN; Wed, 09 Apr 2025 20:13:17 -0400
Received: by mail-lf1-x134.google.com with SMTP id
 2adb3069b0e04-5499614d3d2so277278e87.3
 for <bug-gnu-emacs@HIDDEN>; Wed, 09 Apr 2025 17:13:14 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1744243992; x=1744848792; darn=gnu.org;
 h=to:subject:message-id:date:mime-version:from:from:to:cc:subject
 :date:message-id:reply-to;
 bh=5IJfhZrLjjQ2/m7KpOlT6y/uUZT2czLG5wJJ5Gs72EA=;
 b=LqRxeIJKC++3HhA477Ynga/VT8POzVu/z7oKGlXWDgRT2HRlRv82PKMa+VZFBiBq8v
 HPyGh1OQF8cQF57ANtk6MtyvB5+4NnqMKWFsCQeBRwJkYzbT/MtH4wXE0NvytRl4e6QQ
 OYCoog525jiukkDACZ1IkQoaNiYp/CI++PUQs3bTlcD9HrCztTVQIa6NfD0D3Txe471H
 Gb8n3kNGwecCmFFMLO/JkN2B+JqoKDbVMSel9ytEaZufB3D4H/fCtD7LHgFHWiwooReN
 AeTd1nftdWWKOz3JQ17Loc5fN+Ly5woCwjZZkwLs5d67v/8VrE5tTt2LrhcvTUObxze7
 ySTA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1744243992; x=1744848792;
 h=to:subject:message-id:date:mime-version:from:x-gm-message-state
 :from:to:cc:subject:date:message-id:reply-to;
 bh=5IJfhZrLjjQ2/m7KpOlT6y/uUZT2czLG5wJJ5Gs72EA=;
 b=CJAUrX/UGSaQam2usTPgrGyeXItrOCLhqWgYKYxBuKgVEn6BqjTXu9Od38BqS6HUAi
 3iZqSWW5g77E6ch4d1pwL3jC3pFFRH2NHtmbLatFfYrY9uH+b5eyQ8h6LGZMIIdb02NW
 1SFQM8ClRe3qfxK9rbQyTdyY6YLtmYzdQXRoLnzUyAY4zEjavKl8CSFk9g6EaB7IynvF
 IyWJI41G3cJi99UL7HEQUxBx/RXsg580Yc65BroOCBnWRNnHWZxHyk2BxNaQcYNjQwII
 3wnC+oEy95gfBvNfCI6u6+BLFQ+7IykgKvbhdKPF22mFlNlq17yVG/v0mC2w9Wuz2XW0
 d5Bg==
X-Gm-Message-State: AOJu0YzvG55BrXh8ACq8Z5b19KzEYQcNWnjNGigUADr8ChAaS6mFHvC3
 Svg6J07Fr/NQ0uT9GMVgzrnQpCi+2h1xj8guNuSO54wP33luDngZ7qJ1jNn1Ja9UwTyEJs/36bN
 6uJlqfw8ZIEctN4+asaeKPXA7A+Ud7g==
X-Gm-Gg: ASbGncuIhB6u6KkAi70zNMxYv6gqUY/UFkCe/OHSqP5gRbNr2HhBe5yCtvTWRkbutRb
 8BQDAuoESlP9A5KweQ/rzDL+Ow0RxUS37pVcPBjyYM3TvEPQI43YWRA+7/091GpA5UgzpYBgTlO
 re9U+B4OR642t2IcL0ODUlhQ==
X-Google-Smtp-Source: AGHT+IGSpLs89BlNPV9Ngl7IbMPnZ4hkV1atPX3gGAONK/zfOz7lhlnFENshUWI3mTtTfZwVOODujlTQ08HNuKG8f6U=
X-Received: by 2002:a05:6512:3b8b:b0:54b:117c:118b with SMTP id
 2adb3069b0e04-54d3c646691mr54554e87.56.1744243992261; Wed, 09 Apr 2025
 17:13:12 -0700 (PDT)
Received: from 753933720722 named unknown by gmailapi.google.com with
 HTTPREST; Wed, 9 Apr 2025 17:13:10 -0700
Received: from 753933720722 named unknown by gmailapi.google.com with
 HTTPREST; Wed, 9 Apr 2025 17:13:10 -0700
From: Kristoffer Balintona <krisbalintona@HIDDEN>
MIME-Version: 1.0
Date: Wed, 9 Apr 2025 17:13:10 -0700
X-Gm-Features: ATxdqUH40e5l3gnjl701dLORx0NrDJWbfG3YJf0TQ-9d4ZIQx-CkE5HZ07ZBseA
Message-ID: <CANVbq5=7SGJyjjrsSVxJ6WXssua96iYonyY=bsAYk0Q1X_K9tQ@HIDDEN>
Content-Type: multipart/mixed; boundary="0000000000008f99b406326173b5"
Received-SPF: pass client-ip=2a00:1450:4864:20::134;
 envelope-from=krisbalintona@HIDDEN; helo=mail-lf1-x134.google.com
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_NONE=0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 1.0 (+)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.0 (/)

--0000000000008f99b406326173b5
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Tags: patch

Hello,

Attached is a patch to vtable.el that improves the performance of
vtable-limit-string. This is because of the expensive calls to
string-pixel-width.

The current implementation of the function is O(n), whereas the version
in the attached patch uses a binary search, which has an improved time
complexity of O(n).

I discovered how expensive vtable-limit-string is when working on a
personal project of mine that creates vtables with hundreds of rows.
According to profiler-report, it was by far the largest bottleneck.

Below are two basic benchmarks that show the markedly improved
performance of the version in the attached patch:

        (benchmark-run-compiled 10
          (let ((buf-name "*temp*"))
            (get-buffer-create buf-name)
            ;; The function below is defined by my own project.  It
creates a vtable
            ;; in buffer named BUF-NAME
            (org-roam-folgezettel-list buf-name)
            (kill-buffer buf-name)))
        ;; Original (with GC): (16.77486223 17 6.687552347000008)
        ;; Proposed (with GC): (4.469360591 5 1.919122549000008)


        (let ((gc-cons-threshold most-positive-fixnum))
          (benchmark-run-compiled 10
            (let ((buf-name "*temp*"))
              (get-buffer-create buf-name)
              ;; The function below is defined by my own project.  It
creates a vtable
              ;; in buffer named BUF-NAME
              (org-roam-folgezettel-list buf-name)
              (kill-buffer buf-name))))
        ;; Original (no GC): (10.767429898 0 0.0)
        ;; Proposed (no GC): (2.299831031 0 0.0)


This is my first patch to Emacs, so please let me know if I=E2=80=99ve miss=
ed
any conventions for properly contributing.



In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.49, cairo version 1.18.4) of 2025-03-31 built on UnoriginalName
Windowing system distributor 'Microsoft Corporation', version 11.0.12010000
System Description: Arch Linux

Configured using:
 'configure 'CFLAGS=3D-O2 -march=3Dnative -mtune=3Dnative
 -fomit-frame-pointer' --with-mailutils --with-gtk --with-dbus
 --with-native-compilation'


--=20
With appreciation,
Kristoffer

--0000000000008f99b406326173b5
Content-Type: text/patch; charset="US-ASCII"; 
	name="0001-lisp-emacs-lisp-vtable.el-vtable-limit-string-Use-bi.patch"
Content-Disposition: attachment; 
	filename="0001-lisp-emacs-lisp-vtable.el-vtable-limit-string-Use-bi.patch"
Content-Transfer-Encoding: base64
X-Attachment-Id: 49a071b019e95f75_0.1

RnJvbSA0MWEyNWYxNGMzMGI2NzI0MTU2YzNhNWFjYzM5N2NhYTZmM2FlYWM1IE1vbiBTZXAgMTcg
MDA6MDA6MDAgMjAwMQpGcm9tOiBLcmlzdG9mZmVyIEJhbGludG9uYSA8a3Jpc2JhbGludG9uYUBn
bWFpbC5jb20+CkRhdGU6IFdlZCwgOSBBcHIgMjAyNSAxODo1MDo0OCAtMDUwMApTdWJqZWN0OiBb
UEFUQ0hdIDsgKiBsaXNwL2VtYWNzLWxpc3AvdnRhYmxlLmVsICh2dGFibGUtLWxpbWl0LXN0cmlu
Zyk6IFVzZQogYmluYXJ5IHNlYXJjaC4KCi0tLQogbGlzcC9lbWFjcy1saXNwL3Z0YWJsZS5lbCB8
IDE5ICsrKysrKysrKysrKysrKy0tLS0KIDEgZmlsZSBjaGFuZ2VkLCAxNSBpbnNlcnRpb25zKCsp
LCA0IGRlbGV0aW9ucygtKQoKZGlmZiAtLWdpdCBhL2xpc3AvZW1hY3MtbGlzcC92dGFibGUuZWwg
Yi9saXNwL2VtYWNzLWxpc3AvdnRhYmxlLmVsCmluZGV4IDAwNzg1MTEzZWRiLi4yNjY1Nzc0NDJm
OCAxMDA2NDQKLS0tIGEvbGlzcC9lbWFjcy1saXNwL3Z0YWJsZS5lbAorKysgYi9saXNwL2VtYWNz
LWxpc3AvdnRhYmxlLmVsCkBAIC04NDAsMTAgKzg0MCwyMSBAQCB2dGFibGUtLXNldC1oZWFkZXIt
bGluZQogICAodnRhYmxlLWhlYWRlci1tb2RlIDEpKQogCiAoZGVmdW4gdnRhYmxlLS1saW1pdC1z
dHJpbmcgKHN0cmluZyBwaXhlbHMpCi0gICh3aGlsZSAoYW5kIChsZW5ndGg+IHN0cmluZyAwKQot
ICAgICAgICAgICAgICAoPiAoc3RyaW5nLXBpeGVsLXdpZHRoIHN0cmluZykgcGl4ZWxzKSkKLSAg
ICAoc2V0cSBzdHJpbmcgKHN1YnN0cmluZyBzdHJpbmcgMCAoMS0gKGxlbmd0aCBzdHJpbmcpKSkp
KQotICBzdHJpbmcpCisgICJSZXR1cm4gdGhlIGxvbmdlc3QgcHJlZml4IG9mIFNUUklORyB3aG9z
ZSBwaXhlbCB3aWR0aCBpcyA8PSBQSVhFTFMuIgorICA7OyBQZXJmb3JtIGEgYmluYXJ5IHNlYXJj
aC4gIFRoaXMgaXMgbW9yZSBwZXJmb3JtYW50IHRoYW4gaXRlcmF0aW5nCisgIDs7IHRocm91Z2gg
ZWFjaCBjaGFyYWN0ZXIgaW4gc2VxdWVuY2UuCisgIChsZXQgKChsb3cgMCkKKyAgICAgICAgKGhp
Z2ggKDEtIChsZW5ndGggc3RyaW5nKSkpCisgICAgICAgIHJlc3VsdCkKKyAgICAod2hpbGUgKDw9
IGxvdyBoaWdoKQorICAgICAgKGxldCogKChtaWQgKGZsb29yICgrIGxvdyBoaWdoKSAyKSkKKyAg
ICAgICAgICAgICAoY2FuZGlkYXRlIChzdWJzdHJpbmcgc3RyaW5nIDAgbWlkKSkKKyAgICAgICAg
ICAgICAod2lkdGggKHN0cmluZy1waXhlbC13aWR0aCBjYW5kaWRhdGUpKSkKKyAgICAgICAgKGlm
ICg8PSB3aWR0aCBwaXhlbHMpCisgICAgICAgICAgICAoc2V0cSByZXN1bHQgY2FuZGlkYXRlCisg
ICAgICAgICAgICAgICAgICBsb3cgKDErIG1pZCkpCisgICAgICAgICAgKHNldHEgaGlnaCAoMS0g
bWlkKSkpKSkKKyAgICByZXN1bHQpKQogCiAoZGVmdW4gdnRhYmxlLS1jaGFyLXdpZHRoICh0YWJs
ZSkKICAgKHN0cmluZy1waXhlbC13aWR0aCAocHJvcGVydGl6ZSAieCIgJ2ZhY2UgKHZ0YWJsZS1m
YWNlIHRhYmxlKSkpKQotLSAKMi40OS4wCgo=
--0000000000008f99b406326173b5--




Message sent:


Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-Mailer: MIME-tools 5.505 (Entity 5.505)
Content-Type: text/plain; charset=utf-8
X-Loop: help-debbugs@HIDDEN
From: help-debbugs@HIDDEN (GNU bug Tracking System)
To: Kristoffer Balintona <krisbalintona@HIDDEN>
Subject: bug#77684: Acknowledgement ([PATCH] ; * lisp/emacs-lisp/vtable.el
 (vtable--limit-string): Use binary search)
Message-ID: <handler.77684.B.17442440076955.ack <at> debbugs.gnu.org>
References: <CANVbq5=7SGJyjjrsSVxJ6WXssua96iYonyY=bsAYk0Q1X_K9tQ@HIDDEN>
X-Gnu-PR-Message: ack 77684
X-Gnu-PR-Package: emacs
X-Gnu-PR-Keywords: patch
Reply-To: 77684 <at> debbugs.gnu.org
Date: Thu, 10 Apr 2025 00:14:02 +0000

Thank you for filing a new bug report with debbugs.gnu.org.

This is an automatically generated reply to let you know your message
has been received.

Your message is being forwarded to the package maintainers and other
interested parties for their attention; they will reply in due course.

Your message has been sent to the package maintainer(s):
 bug-gnu-emacs@HIDDEN

If you wish to submit further information on this problem, please
send it to 77684 <at> debbugs.gnu.org.

Please do not send mail to help-debbugs@HIDDEN unless you wish
to report a problem with the Bug-tracking system.

--=20
77684: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D77684
GNU Bug Tracking System
Contact help-debbugs@HIDDEN with problems


Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#77684: [PATCH] ; * lisp/emacs-lisp/vtable.el (vtable--limit-string): Use binary search
Resent-From: Eli Zaretskii <eliz@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sun, 13 Apr 2025 09:28:03 +0000
Resent-Message-ID: <handler.77684.B77684.174453644130272 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 77684
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Kristoffer Balintona <krisbalintona@HIDDEN>
Cc: 77684 <at> debbugs.gnu.org
Received: via spool by 77684-submit <at> debbugs.gnu.org id=B77684.174453644130272
          (code B ref 77684); Sun, 13 Apr 2025 09:28:03 +0000
Received: (at 77684) by debbugs.gnu.org; 13 Apr 2025 09:27:21 +0000
Received: from localhost ([127.0.0.1]:38943 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u3tcV-0007rw-Dq
	for submit <at> debbugs.gnu.org; Sun, 13 Apr 2025 05:27:21 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:51734)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1u3tcG-0007oR-O6
 for 77684 <at> debbugs.gnu.org; Sun, 13 Apr 2025 05:27:06 -0400
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 <eliz@HIDDEN>)
 id 1u3tcB-0003tL-1i; Sun, 13 Apr 2025 05:26:59 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From:
 Date; bh=VB/SGZAvpQFQYMM5tfIx5NMWMYa3owI9RFycnUK9RxE=; b=PWw47pcwkuik3BLDOmDl
 3l6FrB8PCQhZq6JSIXVUHOQCnewIPrQP082eiLjnLJHuStw1g1VqX0VAf4pOMP94D7SMrhdzyiYC5
 RYy/CETPzhdrcuAPF3wLAgSbwJ6xA5xAx6ygUyAjkQPCW4xhsFeOMDK2DZMZDjZja/8KqVKIu6qgI
 L/YgeSwJYlowbA8VRwIr7s70vogX0sjAoS1VbH1ETz2yDVyYOxGU37HokMk5wY3L+1wM7V+7AnNkX
 gE1JoSRXums1FlkAJBwGYzll82sP5b5BXzzfsAQ2bMrj3H/uSjL/lfcjsMJvEOGyyXYyP8QW91weK
 c466CTdxUMGpzg==;
Date: Sun, 13 Apr 2025 12:26:54 +0300
Message-Id: <861ptwl8dd.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
In-Reply-To: <CANVbq5=7SGJyjjrsSVxJ6WXssua96iYonyY=bsAYk0Q1X_K9tQ@HIDDEN>
 (message from Kristoffer Balintona on Wed, 9 Apr 2025 17:13:10 -0700)
References: <CANVbq5=7SGJyjjrsSVxJ6WXssua96iYonyY=bsAYk0Q1X_K9tQ@HIDDEN>
MIME-version: 1.0
Content-type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: -2.3 (--)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Kristoffer Balintona <krisbalintona@HIDDEN>
> Date: Wed, 9 Apr 2025 17:13:10 -0700
> 
> Attached is a patch to vtable.el that improves the performance of
> vtable-limit-string. This is because of the expensive calls to
> string-pixel-width.
> 
> The current implementation of the function is O(n), whereas the version
> in the attached patch uses a binary search, which has an improved time
> complexity of O(n).
> 
> I discovered how expensive vtable-limit-string is when working on a
> personal project of mine that creates vtables with hundreds of rows.
> According to profiler-report, it was by far the largest bottleneck.

Binary search will only work if adding or removing a character will
always change the result of string-pixel-width.  But this is not true
in general, due to character composition and other Emacs display
features.  Here's a simple example of such an issue:

  (string-pixel-width "a")
   => 9
  (string-pixel-width (concat "a" "́"))
   => 9

So adding a character doesn't affect the result of string-pixel-width,
in this case because the two characters will be displayed by a single
glyph that combines the base character 'a' and the acute accent.

Did you try your modified code in such situations, or did you only try
it with simple characters that never combine?




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#77684: [PATCH] ; * lisp/emacs-lisp/vtable.el (vtable--limit-string): Use binary search
Resent-From: Ship Mints <shipmints@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sun, 13 Apr 2025 11:16:05 +0000
Resent-Message-ID: <handler.77684.B77684.17445429324761 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 77684
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Eli Zaretskii <eliz@HIDDEN>
Cc: 77684 <at> debbugs.gnu.org, Kristoffer Balintona <krisbalintona@HIDDEN>
Received: via spool by 77684-submit <at> debbugs.gnu.org id=B77684.17445429324761
          (code B ref 77684); Sun, 13 Apr 2025 11:16:05 +0000
Received: (at 77684) by debbugs.gnu.org; 13 Apr 2025 11:15:32 +0000
Received: from localhost ([127.0.0.1]:39889 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u3vJC-0001EW-Pz
	for submit <at> debbugs.gnu.org; Sun, 13 Apr 2025 07:15:31 -0400
Received: from mail-ua1-x92a.google.com ([2607:f8b0:4864:20::92a]:57749)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <shipmints@HIDDEN>)
 id 1u3vJA-0001DR-Os
 for 77684 <at> debbugs.gnu.org; Sun, 13 Apr 2025 07:15:29 -0400
Received: by mail-ua1-x92a.google.com with SMTP id
 a1e0cc1a2514c-86d5e42c924so2937205241.3
 for <77684 <at> debbugs.gnu.org>; Sun, 13 Apr 2025 04:15:28 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1744542923; x=1745147723; darn=debbugs.gnu.org;
 h=cc:to:subject:message-id:date:from:in-reply-to:references
 :mime-version:from:to:cc:subject:date:message-id:reply-to;
 bh=RMmLB3tC9h/26e6FMkCczpgoL4PfaymyEkG9IGML/EU=;
 b=mXbtgsMEHQGu60vhXeqWVw7fgy55kSd3UJ82LWBgnTgsfzx8PWsoUvXCTWf6fof+yb
 ZRrmvo+mferhKtcQ5Mb9O/Ns2Zic3C4RU6wStecDxxGbhpPx0ARAjmQcs8sML3lvzMKC
 pVelN8Fy2tSwThg9Kjf8HKpD9NlWi/ja3VhRM0UK+oaY8ayDKDiwcGaOuMWnh6vIIGuR
 ecc2tgdMoU9H43FoQCeNjf2hHIUWzd2BGJ8KTcMKBVhPpzp9s/jxyyZQxUFdvFhclG1I
 6cUd1gwFOTyof4XcTwAKWe2Rk1SpJ6V/BWz2bMSW2sO2VCbzUZcHSEXSr2fIoNvAJ+WC
 mWUg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1744542923; x=1745147723;
 h=cc:to:subject:message-id:date:from:in-reply-to:references
 :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id
 :reply-to;
 bh=RMmLB3tC9h/26e6FMkCczpgoL4PfaymyEkG9IGML/EU=;
 b=VVDIV/D6DYOUpJncoHJmqW8oZNFeZsK/RijsYPQq0fNrVmnfNaTdk8VcuOn537TVoX
 5Azonp769rdO69S3CfUdgzKe0ux3zoC3sd3MHXMM7DCZX9TStj4y21YVQYxYINNb6VpH
 v2YUWqG9YXbkI3eGwQ/VWxQSNfMJknHR18HO6geKkWljdm0PxmADp4xSs1Q+2Td7rREF
 /cSJPD3RHgeh4lgmpqYMy3DO3uav4Y3ldtkN2XkSkOggJpHuEataEw6gmFipcfS8O+Qd
 NZ0AR3eXs7FvukMEKuO2nIFkouPzeIqoXZP5Zhoa4NdjIp9AS0GF1YxF+aqMmaFV9Nv9
 dYiQ==
X-Forwarded-Encrypted: i=1;
 AJvYcCXhYmZ/AmzqLXTKDEfhdVC2iRZhRxWr9heYJBRGFAeb9TkHrGgS+fu9yLXB/IUD4uuQuajcCg==@debbugs.gnu.org
X-Gm-Message-State: AOJu0Yz5joE8UDmUjfI46ANPOV1X1PTLYPq5byeeMYH27GbRtAA2yTyo
 N6NsZW+cj6ANR5EY9hrepGQe7QnTkiGis3dgyzSdJjD7WSaMj0/LNSuvM6PE2oxlc4yTIY65tI9
 Gn7xa+XzR4aWr8ZRDIeQaW7i9jBM=
X-Gm-Gg: ASbGncv1wiKkFt4aseUeW77nZjQZB3IcN5xqWsMSaEctwZRajsyymyUyz46TSiarfzE
 duuEesN2Tf+gNJiqCR4XMNvX7DNa7K11pufO47iXNwHVXIk6sgkPJMHaQtKs02pnooKa11xz+n1
 0yL8Pcdrx62VYwEtGZYGe236W082HKvkIl
X-Google-Smtp-Source: AGHT+IFVEZotun5fOaPshPsZapNKbSA9Yc/6gFongRoEzccOLA7T8Peo3LhCGKLBm4UKSGlZKh977+yBX7ekhGiS7lM=
X-Received: by 2002:a05:6102:fa5:b0:4bb:9b46:3f92 with SMTP id
 ada2fe7eead31-4c9e4ec68e9mr6506467137.1.1744542922630; Sun, 13 Apr 2025
 04:15:22 -0700 (PDT)
MIME-Version: 1.0
References: <CANVbq5=7SGJyjjrsSVxJ6WXssua96iYonyY=bsAYk0Q1X_K9tQ@HIDDEN>
 <861ptwl8dd.fsf@HIDDEN>
In-Reply-To: <861ptwl8dd.fsf@HIDDEN>
From: Ship Mints <shipmints@HIDDEN>
Date: Sun, 13 Apr 2025 07:15:11 -0400
X-Gm-Features: ATxdqUHVbVOk1nyH-vuq8dHJSDfldE5VysqG-uhnPUfkeZmjxpsA2q1xY3p0yXQ
Message-ID: <CAN+1HbrHQUGyg0BEMVQpHocCUNqmW=PsVjLe7mTu8haRa7mk7w@HIDDEN>
Content-Type: multipart/alternative; boundary="00000000000032ec690632a70df7"
X-Spam-Score: 0.0 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--00000000000032ec690632a70df7
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Sun, Apr 13, 2025 at 5:28=E2=80=AFAM Eli Zaretskii <eliz@HIDDEN> wrote:

> > From: Kristoffer Balintona <krisbalintona@HIDDEN>
> > Date: Wed, 9 Apr 2025 17:13:10 -0700
> >
> > Attached is a patch to vtable.el that improves the performance of
> > vtable-limit-string. This is because of the expensive calls to
> > string-pixel-width.
> >
> > The current implementation of the function is O(n), whereas the version
> > in the attached patch uses a binary search, which has an improved time
> > complexity of O(n).
> >
> > I discovered how expensive vtable-limit-string is when working on a
> > personal project of mine that creates vtables with hundreds of rows.
> > According to profiler-report, it was by far the largest bottleneck.
>
> Binary search will only work if adding or removing a character will
> always change the result of string-pixel-width.  But this is not true
> in general, due to character composition and other Emacs display
> features.  Here's a simple example of such an issue:
>
>   (string-pixel-width "a")
>    =3D> 9
>   (string-pixel-width (concat "a" "=CC=81"))
>    =3D> 9
>
> So adding a character doesn't affect the result of string-pixel-width,
> in this case because the two characters will be displayed by a single
> glyph that combines the base character 'a' and the acute accent.
>
> Did you try your modified code in such situations, or did you only try
> it with simple characters that never combine?
>

You can avoid the cost of this string metric by supplying your own global
displayer function for the table or a column-specific displayer function.

Apropos timing as I've been spending some time with vtable and I have a
bunch of bug fixes and a few enhancements coming.  One will slow down that
function a little more...vtable breaks under remapped fonts; e.g., when
using text-scale-adjust so I've fixed that (I have some pixel adjustments
left on the header which still gets out of alignment a little).

--00000000000032ec690632a70df7
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div class=3D"gmail_default" style=3D"fon=
t-family:monospace"><span style=3D"font-family:Arial,Helvetica,sans-serif">=
On Sun, Apr 13, 2025 at 5:28=E2=80=AFAM Eli Zaretskii &lt;<a href=3D"mailto=
:eliz@HIDDEN">eliz@HIDDEN</a>&gt; wrote:</span></div></div><div class=3D"=
gmail_quote gmail_quote_container"><blockquote class=3D"gmail_quote" style=
=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding=
-left:1ex">&gt; From: Kristoffer Balintona &lt;<a href=3D"mailto:krisbalint=
ona@HIDDEN" target=3D"_blank">krisbalintona@HIDDEN</a>&gt;<br>
&gt; Date: Wed, 9 Apr 2025 17:13:10 -0700<br>
&gt; <br>
&gt; Attached is a patch to vtable.el that improves the performance of<br>
&gt; vtable-limit-string. This is because of the expensive calls to<br>
&gt; string-pixel-width.<br>
&gt; <br>
&gt; The current implementation of the function is O(n), whereas the versio=
n<br>
&gt; in the attached patch uses a binary search, which has an improved time=
<br>
&gt; complexity of O(n).<br>
&gt; <br>
&gt; I discovered how expensive vtable-limit-string is when working on a<br=
>
&gt; personal project of mine that creates vtables with hundreds of rows.<b=
r>
&gt; According to profiler-report, it was by far the largest bottleneck.<br=
>
<br>
Binary search will only work if adding or removing a character will<br>
always change the result of string-pixel-width.=C2=A0 But this is not true<=
br>
in general, due to character composition and other Emacs display<br>
features.=C2=A0 Here&#39;s a simple example of such an issue:<br>
<br>
=C2=A0 (string-pixel-width &quot;a&quot;)<br>
=C2=A0 =C2=A0=3D&gt; 9<br>
=C2=A0 (string-pixel-width (concat &quot;a&quot; &quot;=CC=81&quot;))<br>
=C2=A0 =C2=A0=3D&gt; 9<br>
<br>
So adding a character doesn&#39;t affect the result of string-pixel-width,<=
br>
in this case because the two characters will be displayed by a single<br>
glyph that combines the base character &#39;a&#39; and the acute accent.<br=
>
<br>
Did you try your modified code in such situations, or did you only try<br>
it with simple characters that never combine?<br></blockquote><div><br></di=
v><div class=3D"gmail_default" style=3D"font-family:monospace">You can avoi=
d the cost of this string metric by supplying your own global displayer fun=
ction for the table or a column-specific displayer function.</div><div clas=
s=3D"gmail_default" style=3D"font-family:monospace"><br></div><div class=3D=
"gmail_default" style=3D"font-family:monospace">Apropos timing as I&#39;ve =
been spending some time with vtable and I have a bunch of bug fixes and a f=
ew enhancements coming.=C2=A0 One will slow down that function a little mor=
e...vtable breaks under remapped fonts; e.g., when using text-scale-adjust =
so I&#39;ve fixed that (I have some pixel adjustments left on the header wh=
ich still gets out of alignment a little).</div></div></div>

--00000000000032ec690632a70df7--





Last modified: Sun, 13 Apr 2025 11:30:04 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.