From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.bugs Subject: bug#75342: [PATCH] Speed up asynchronous man page fontifying Date: Sat, 4 Jan 2025 01:22:03 -0600 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="00000000000086a0ca062adc4048" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18535"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Juri Linkov To: 75342@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jan 04 08:23:14 2025 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 1tTyV7-0004hq-Bi for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 04 Jan 2025 08:23:13 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tTyUz-0007lv-2q; Sat, 04 Jan 2025 02:23:05 -0500 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 1tTyUx-0007li-C6 for bug-gnu-emacs@gnu.org; Sat, 04 Jan 2025 02:23:03 -0500 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 1tTyUx-0007rz-3G for bug-gnu-emacs@gnu.org; Sat, 04 Jan 2025 02:23:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=Date:MIME-Version:From:To:Subject; bh=fhnwegifMvrXheNDIit087UoTnlH3c5sa0FI/se65U4=; b=bdeWCuxB5wwoqgZQeqSnKmEAvfscQmvYmQuFLfoyLf/u36mwdxDb7H1GWmr6/QUrsQpfA+ER2hTGKgJ9huk4OjJ4jShMcFOt/J6i1QNoE70kgCtyQ9fDVa2OeecHLzr9kRbmikQN1hXpUj8pvQXNe/q98zvCvMTsZJunVu2WLmGsi3DG9dZegkVFCLYffadFdSXRYjlIZUi1duTIPAvf9l0ihtrdy/wZJAiYjj8f7IaFAEFsHmEPf1I68Fa8tar1ieil96blVhRtZZQ636xnQtQFHzKGMTYBc1k/Az+4KrcGOm/38pPGUXNHARtrLOrKECsfVqDjSS+UNdfpg0yVqQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tTyUw-0007qF-50; Sat, 04 Jan 2025 02:23:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: juri@linkov.net, bug-gnu-emacs@gnu.org Resent-Date: Sat, 04 Jan 2025 07:23:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 75342 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: Juri Linkov Original-Received: via spool by submit@debbugs.gnu.org id=B.173597534030087 (code B ref -1); Sat, 04 Jan 2025 07:23:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 4 Jan 2025 07:22:20 +0000 Original-Received: from localhost ([127.0.0.1]:53170 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tTyUF-0007pC-QC for submit@debbugs.gnu.org; Sat, 04 Jan 2025 02:22:20 -0500 Original-Received: from lists.gnu.org ([2001:470:142::17]:59302) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tTyUD-0007ow-Q2 for submit@debbugs.gnu.org; Sat, 04 Jan 2025 02:22:18 -0500 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 1tTyU7-0007jt-6w for bug-gnu-emacs@gnu.org; Sat, 04 Jan 2025 02:22:11 -0500 Original-Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tTyU3-0007pl-8W for bug-gnu-emacs@gnu.org; Sat, 04 Jan 2025 02:22:10 -0500 Original-Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-5d3cf094768so20804003a12.0 for ; Fri, 03 Jan 2025 23:22:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735975324; x=1736580124; darn=gnu.org; h=to:subject:message-id:date:mime-version:from:from:to:cc:subject :date:message-id:reply-to; bh=fhnwegifMvrXheNDIit087UoTnlH3c5sa0FI/se65U4=; b=IosZWxI9inb9p1wBgHTgpg6dxQiIH/PPjYB97Z01+SJ1nfZAUnuEwAiN60AhWUAXz2 J3qHt9mMIVPloohVrw+p5PKSLHd0GqiU9WpcTyuXnfuY0kCrddyP9Qzu5LnM+H+6Hu3l H/KabU6toHP/rF/XHv9hxx2V0JmND7E2uxHnZ3rzS3p7Gn01N10ETG5NoRzQGvv/9m/+ xr+vFpYpbrxNLtzs0tRaueVrTHyAqv+4b0onNbkBnd+7gNLb7EOqFwIrlVawV1dn4hKK 63S5GcmZa3ZKense8bH+WlHUWjHHqcEoshZy94LOaZxYwqc24m8uAnFO4+A/I2DtngNw YBsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735975324; x=1736580124; h=to:subject:message-id:date:mime-version:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=fhnwegifMvrXheNDIit087UoTnlH3c5sa0FI/se65U4=; b=PFImZyAEKfeKi5Q/Z/qBnxZDCfkXEer9Eu81lfsSD4sV0p2du0JE2jNmOWrsjK8qwb zgn/Ow185NZlLFBLdexlvE6cFtYYP3UPc85fGhuZwCVbjQFglmxc7x5/ioeZwJ6DdQRT Xbfz1QQua8SUnqQ5mVFNOAUWC4p9q5uOlFXeazMSEewr+fcx17/hHoMOLBcuclIvFQph 2O35AomUZi4qti9kaBnLe18MAkk4U0v7tciy3NtCZJ/dnNLYd7il7x+kyYHXY0dVIZbN lO0FzoZ0R6brYjyIv1xpiQq0BXtABocDs6+aUD+0KKCgeHjB3PVsus8tUcPlwpVTz2ip amiw== X-Gm-Message-State: AOJu0YzsRX0ExdYBUEe47fqhidbjx//6ENQ7bFW6FJXpKE+VutisNFTS bM7l1+8mebvoRMmKcFranU6zF154dy/QFw+xhLb1YPUITI8zM3Zt+iRmgCNM1IAG+AtneMzV+Hk R+m9tmphhq2Vr/rrrL3rKtTBivyACAUcB X-Gm-Gg: ASbGncvdhzifGW9bBwyH86sZ62Pr/TJDptCqMIVjlYzr1lzDNhNemvnvnEweUiP5DzP He0fIY78kN6sVCpDAfbBs5I6qu3SD3/XY7h94UiFw X-Google-Smtp-Source: AGHT+IHJ+zG3+Hg0whJw7sfwy5B3Mq5kKqxIzKhi3kze4UxMwLyljoQveYTF/062Osf84BQ37AOk3r9Ot6DcYbBldWI= X-Received: by 2002:a05:6402:270a:b0:5cf:c97c:8206 with SMTP id 4fb4d7f45d1cf-5d81ddfdb2emr39603465a12.25.1735975323985; Fri, 03 Jan 2025 23:22:03 -0800 (PST) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Sat, 4 Jan 2025 01:22:03 -0600 Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=stefankangas@gmail.com; helo=mail-ed1-x534.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-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:298328 Archived-At: --00000000000086a0ca062adc4048 Content-Type: text/plain; charset="UTF-8" Severity: wishlist The below patch makes asynchronous fontifying of man pages faster. After typing `M-x man RET gcc-14 RET`, it takes around 5 minutes on this fast MacBook Pro M2 (2022) machine until the whole 1.43 MiB man page is displayed. With a hot cache, the best time I have managed to measure is 173.432 seconds. We seem to call `man--maybe-fontify-manpage` many times on very small chunks: on my machine, it processes ~30 characters at a time. Things get substantially faster if we make `Man-bgproc-filter` fontify the buffer in much larger chunks. The main drawback of doing this is that we risk very briefly seeing an incorrect display flash by in the man buffer (e.g., with `end-of-buffer`). My measurements show that 32 KiB might be a good choice, and gives a ~95% speedup: | Chunk size (KiB) | Completion time (s) | |------------------+---------------------| | 4 | 29.3 | | 8 | 18.2 | | 16 | 12.7 | | 32 | 7.4 | | 64 | 6.5 | | 128 | 5.4 | Is this the best approach to optimize something like this, or am I overlooking something obvious? Note that I didn't add a variable for the chunk size, but we could easily add one, if that'd be useful. When I set `Man-prefer-synchronous-call` to t, it takes ~1.8 seconds to process the same page. I guess that this is the lower bound for how fast we could make the asynchronous call. Please see the attached. --00000000000086a0ca062adc4048 Content-Type: text/x-patch; charset="US-ASCII"; name="0001-Fontify-man-page-in-32-KiB-chunks.patch" Content-Disposition: attachment; filename="0001-Fontify-man-page-in-32-KiB-chunks.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: 6eea4916ec9a50df_0.1 RnJvbSAyZjY3N2NmNDQ1N2FlNGEyZmRmMDJjZWU2NTg5ODhkYTNhMjdkYWZjIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBTdGVmYW4gS2FuZ2FzIDxzdGVmYW5rYW5nYXNAZ21haWwuY29t PgpEYXRlOiBTYXQsIDQgSmFuIDIwMjUgMDc6Mzg6MzMgKzAxMDAKU3ViamVjdDogW1BBVENIXSBG b250aWZ5IG1hbiBwYWdlIGluIDMyIEtpQiBjaHVua3MKCiogbGlzcC9tYW4uZWwgKG1hbi0tYmdw cm9jLWZpbHRlci1mb250aWZ5KTogTmV3IGZ1bmN0aW9uLgooTWFuLWJncHJvYy1maWx0ZXIpOiBV c2UgYWJvdmUgbmV3IGZ1bmN0aW9uOyBmb250aWZ5IGluIDMyIEtpQiBjaHVua3MuCihNYW4tYmdw cm9jLXNlbnRpbmVsKTogVXNlIGFib3ZlIG5ldyBmdW5jdGlvbi4KKG1hbi0tYmdwcm9jLWZpbHRl ci1sYXN0LXBvcyk6IE5ldyB2YXJpYWJsZS4KKE1hbi1nZXRwYWdlLWluLWJhY2tncm91bmQpOiBT ZXQgYWJvdmUgbmV3IHZhcmlhYmxlIHRvIDAuCi0tLQogbGlzcC9tYW4uZWwgfCAzMiArKysrKysr KysrKysrKysrKysrKystLS0tLS0tLS0tLQogMSBmaWxlIGNoYW5nZWQsIDIxIGluc2VydGlvbnMo KyksIDExIGRlbGV0aW9ucygtKQoKZGlmZiAtLWdpdCBhL2xpc3AvbWFuLmVsIGI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AJICAgICAgKGluc2VydCBzdHJpbmcpCi0JICAgICAgKHNhdmUtcmVz dHJpY3Rpb24KLQkJKG5hcnJvdy10by1yZWdpb24KLQkJIChzYXZlLWV4Y3Vyc2lvbgotCQkgICAo Z290by1jaGFyIGJlZykKLSAgICAgICAgICAgICAgICAgICA7OyBQcm9jZXNzIHdob2xlIHNlY3Rp b25zIChCdWcjMzY5MjcpLgotICAgICAgICAgICAgICAgICAgIChNYW4tcHJldmlvdXMtc2VjdGlv biAxKQotICAgICAgICAgICAgICAgICAgIChwb2ludCkpCi0JCSAocG9pbnQpKQotCQkobWFuLS1t YXliZS1mb250aWZ5LW1hbnBhZ2UpKQorICAgICAgICAgICAgICA7OyBDaHVuayB0aGUgcHJvY2Vz c2luZy4KKyAgICAgICAgICAgICAgKHdoZW4gKD49ICgtIGJlZyBtYW4tLWJncHJvYy1maWx0ZXIt bGFzdC1wb3MpIDApCisgICAgICAgICAgICAgICAgKG1hbi0tYmdwcm9jLWZpbHRlci1mb250aWZ5 KSkKIAkgICAgICAoc2V0LW1hcmtlciAocHJvY2Vzcy1tYXJrIHByb2Nlc3MpIChwb2ludC1tYXgp KSkpKSkpKSkKIAogKGRlZnVuIE1hbi1iZ3Byb2Mtc2VudGluZWwgKHByb2Nlc3MgbXNnKQpAQCAt MTU2MCw2ICsxNTY5LDcgQEAgTWFuLWJncHJvYy1zZW50aW5lbAogCSAgICAoc2V0LXByb2Nlc3Mt YnVmZmVyIHByb2Nlc3MgbmlsKSkKIAogICAgICAgKHdpdGgtY3VycmVudC1idWZmZXIgTWFuLWJ1 ZmZlcgorICAgICAgICAobWFuLS1iZ3Byb2MtZmlsdGVyLWZvbnRpZnkpCiAJKHNhdmUtZXhjdXJz aW9uCiAJICAobGV0ICgoY2FzZS1mb2xkLXNlYXJjaCBuaWwpCiAgICAgICAgICAgICAgICAgKGlu aGliaXQtcmVhZC1vbmx5IHQpKQotLSAKMi40Ny4xCgo= --00000000000086a0ca062adc4048--