From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#63861: [PATCH] pp.el: New "pretty printing" code Date: Wed, 07 Jun 2023 11:27:35 -0400 Message-ID: References: <87edmnics1.fsf@posteo.net> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6382"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 63861@debbugs.gnu.org To: Thierry Volpiatto Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 07 17:28:21 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 1q6v5A-0001Sh-V5 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 07 Jun 2023 17:28:21 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q6v4v-0002rU-Ff; Wed, 07 Jun 2023 11:28:05 -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 1q6v4t-0002X5-0t for bug-gnu-emacs@gnu.org; Wed, 07 Jun 2023 11:28:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q6v4s-0007oB-KN for bug-gnu-emacs@gnu.org; Wed, 07 Jun 2023 11:28:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q6v4s-0004tU-3i for bug-gnu-emacs@gnu.org; Wed, 07 Jun 2023 11:28:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 07 Jun 2023 15:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63861 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-Cc: "Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors" , 63861@debbugs.gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.168615166318777 (code B ref -1); Wed, 07 Jun 2023 15:28:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 7 Jun 2023 15:27:43 +0000 Original-Received: from localhost ([127.0.0.1]:54526 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q6v4Y-0004sg-Os for submit@debbugs.gnu.org; Wed, 07 Jun 2023 11:27:43 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:58430) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q6v4W-0004sX-Ma for submit@debbugs.gnu.org; Wed, 07 Jun 2023 11:27:41 -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 1q6v4W-0000hv-BO for bug-gnu-emacs@gnu.org; Wed, 07 Jun 2023 11:27:40 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q6v4U-0007k5-IL for bug-gnu-emacs@gnu.org; Wed, 07 Jun 2023 11:27:40 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 30D3180504; Wed, 7 Jun 2023 11:27:37 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id ED547804F6; Wed, 7 Jun 2023 11:27:35 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1686151656; bh=5jZ6luSq4tjv/AHsp8bV8kbUZF0uBnjbcXdkfi6NNvU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=JNjeXEMsp/hbqAb+v7KnwZ0Cuzdp1tJQ3QiY751pr6rjjQ9ulTXvRWZVzAGxQ4XBf 5MWV3XvtBFGlk0RPCnxSuW+dzVP3E1LS/1OKH7dXxP7HlOfLIfD8zkRzgH0ElCqKjI MUIG2rOd3S62B9Y+HVNC0PDJS9RdX+Q1dcSAhQcJfkxohoY+5ma4GCht4f3M49Zejp 3h1Dv2+18qcMxBQl3XnooCPyujlGKv9yzYLDtN6WKqJ1qv9Rd6yRIKx+MVXfxu9Yn2 DBm9/zHTPRMqvpyodol3WFDCqJ7u2wpJJNK4j+xuaLtqIzEe651LVeYKZk/u/yiNuh n/verMXwU97vA== Original-Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id DC2E9120508; Wed, 7 Jun 2023 11:27:35 -0400 (EDT) In-Reply-To: <87edmnics1.fsf@posteo.net> (Thierry Volpiatto's message of "Wed, 07 Jun 2023 14:10:22 +0000") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=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:263076 Archived-At: > I tried your code and it looks very slow (but looks nice once printed). > Testing on my bookmark-alist printed in some buffer. > Here with a slightly modified version of pp-buffer (not much faster than > the original one): > > (benchmark-run-compiled 1 (pp-buffer)) > =3D> (6.942135047 0 0.0) > And here with your version (using pp-region): > (benchmark-run-compiled 1 (pp-buffer)) > =3D> (46.141411097 0 0.0) > > For describe variable I use a modified version of `pp` which is very > fast (nearly instant to pretty print value above) but maybe unsafe with > some vars, didn't have any problems though, see > https://github.com/thierryvolpiatto/emacs-config/blob/main/describe-varia= ble.el. Beside the actual way we choose when to insert \n, the main difference w.r.t performance tends to come from the fact that the new code relies on `lisp-indent-line` rather than `lisp-indent-region`. In many cases it doesn't make much difference performancewise, but indeed there are cases where the difference is significant (more specifically where it makes the code O(N=B2) rather than O(N)). I've been using the patch below for a while and I should probably include it the `pp-region` patch. Can you check whether it helps for your case? Stefan diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index d44c9d6e23d..9914ededb85 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el @@ -876,7 +876,7 @@ lisp-ppss 2 (counting from 0). This is important for Lisp indentation." (unless pos (setq pos (point))) (let ((pss (syntax-ppss pos))) - (if (nth 9 pss) + (if (and (not (nth 2 pss)) (nth 9 pss)) (let ((sexp-start (car (last (nth 9 pss))))) (parse-partial-sexp sexp-start pos nil nil (syntax-ppss sexp-sta= rt))) pss)))