From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Raffael Stocker Newsgroups: gmane.emacs.bugs Subject: bug#67536: 29.1; Calc mode's math-read-preprocess-string conses unnecessarily Date: Thu, 30 Nov 2023 19:28:27 +0100 Message-ID: References: <83h6l367zx.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25945"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.10.8; emacs 29.1 Cc: 67536@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 30 20:03:13 2023 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 1r8mJd-0006Yg-IG for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 30 Nov 2023 20:03:13 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8mJL-0008NP-TF; Thu, 30 Nov 2023 14:02:56 -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 1r8mJK-0008NF-9s for bug-gnu-emacs@gnu.org; Thu, 30 Nov 2023 14:02:54 -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 1r8mJK-00082L-14 for bug-gnu-emacs@gnu.org; Thu, 30 Nov 2023 14:02:54 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r8mJS-0007aQ-0i for bug-gnu-emacs@gnu.org; Thu, 30 Nov 2023 14:03:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Raffael Stocker Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 30 Nov 2023 19:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67536 X-GNU-PR-Package: emacs Original-Received: via spool by 67536-submit@debbugs.gnu.org id=B67536.170137092429077 (code B ref 67536); Thu, 30 Nov 2023 19:03:01 +0000 Original-Received: (at 67536) by debbugs.gnu.org; 30 Nov 2023 19:02:04 +0000 Original-Received: from localhost ([127.0.0.1]:54496 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r8mIV-0007Ys-Hp for submit@debbugs.gnu.org; Thu, 30 Nov 2023 14:02:03 -0500 Original-Received: from mail-out.m-online.net ([212.18.0.10]:47688) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r8mIS-0007YS-PJ for 67536@debbugs.gnu.org; Thu, 30 Nov 2023 14:02:01 -0500 Original-Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4Sh5CL6nq9z1sBpn; Thu, 30 Nov 2023 20:01:50 +0100 (CET) Original-Received: from localhost (dynscan1.mnet-online.de [192.168.6.68]) by mail.m-online.net (Postfix) with ESMTP id 4Sh5CL4sryz1qqlW; Thu, 30 Nov 2023 20:01:50 +0100 (CET) X-Virus-Scanned: amavis at mnet-online.de Original-Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.68]) (amavis, port 10024) with ESMTP id 1j0Fodw37ad5; Thu, 30 Nov 2023 20:01:49 +0100 (CET) X-Auth-Info: QFlyvuzxXRic5dgVtXOVXjgrVwOTNyEDKcpdIHmQ6XgzniBgiVQ21VGwl3SUdXqH Original-Received: from Whiteflame (ppp-212-114-182-107.dynamic.mnet-online.de [212.114.182.107]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Thu, 30 Nov 2023 20:01:49 +0100 (CET) In-reply-to: <83h6l367zx.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:275292 Archived-At: Eli Zaretskii writes: >> ... >> 60,252,646 96% - org-ctrl-c-ctrl-c >> 60,248,166 96% - org-table-calc-current-TBLFM >> 60,216,431 96% - funcall-interactively >> 60,205,119 96% - org-table-recalculate >> 49,094,651 78% - org-table-eval-formula >> 32,624,631 52% - calc-eval >> 32,624,631 52% - calc-do-calc-eval >> 32,620,487 52% - calc-do-calc-eval >> 32,611,151 52% - math-read-exprs >> 29,388,838 47% + math-read-preprocess-string >> 2,343,257 3% + math-read-expr-list > > This is not memory usage, this is CPU usage measured by using > memory-allocation functions as triggers to probe for the function that > is being executed. So its evidence about consing and GC pressure is > indirect at best. > > Can you instead look at the values of gcs-done and gc-elapsed before > and after running the offending code, and show the delta of each one > of them, with and without your proposed changes? Then we will see a > much more direct evidence about the number of GC cycles and the time > spent in GC, and could make the decision about how to improve the > situation. I defined the following advice: --8<---------------cut here---------------start------------->8--- (defun my-gc-status (orig-fun &rest args) (let* ((done-bf gcs-done) (elapsed-bf gc-elapsed) (res (apply orig-fun args)) (done-af gcs-done) (elapsed-af gc-elapsed)) (message "before:\n\tgcs-done: %d, gc-elapsed: %f" done-bf elapsed-bf) (message "after:\n\tgcs-done: %d, difference: %d\n\tgc-elapsed: %f, dif= ference: %f" done-af (- done-af done-bf) elapsed-af (- elapsed-af elapsed-bf)) res)) (advice-add 'org-table-recalculate :around #'my-gc-status) --8<---------------cut here---------------end--------------->8--- I had to put it around =E2=80=98org-table-recalculate=E2=80=99 instead of =E2=80=98math-read-preprocess-string=E2=80=99 as all the functions below org-table-recalculate are called very often and have small individual contributions. With the original =E2=80=98math-read-preprocess-string=E2= =80=99 I get the following typical result: --8<---------------cut here---------------start------------->8--- before: gcs-done: 854, gc-elapsed: 170.601313 after: gcs-done: 859, difference: 5 gc-elapsed: 171.671042, difference: 1.069729 --8<---------------cut here---------------end--------------->8--- I ran the command about twenty times and almost always got the gcs-done difference of 5, with the occasional 4. The gc-elapsed is fairly consistent at 1.07 for the 5 GC runs. The modified version yields this typical output: --8<---------------cut here---------------start------------->8--- before: gcs-done: 906, gc-elapsed: 181.417292 after: gcs-done: 908, difference: 2 gc-elapsed: 181.847972, difference: 0.430679 --8<---------------cut here---------------end--------------->8--- Again, the gcs-done difference is quite stable at 2, with the occasional 3, the gc-elapsed is also fairly consistent at 0.43 for the 2 GC runs. So we have about a factor of 2.5 between the elapsed GC times for the two versions. Regards, Raffael