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: Fri, 09 Jun 2023 10:59:18 -0400 Message-ID: References: <83fs799jmi.fsf@gnu.org> <871qirdi3a.fsf@gmail.com> <87cz25b9rw.fsf@gmail.com> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7773"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , 63861@debbugs.gnu.org To: Visuwesh Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jun 09 17:00:18 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 1q7db8-0001l9-3e for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 09 Jun 2023 17:00:18 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q7dau-0004ed-H8; Fri, 09 Jun 2023 11:00:04 -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 1q7das-0004c0-Sc for bug-gnu-emacs@gnu.org; Fri, 09 Jun 2023 11:00:02 -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 1q7das-0002KN-EU for bug-gnu-emacs@gnu.org; Fri, 09 Jun 2023 11:00:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q7dar-0004cx-Rz for bug-gnu-emacs@gnu.org; Fri, 09 Jun 2023 11:00:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 09 Jun 2023 15:00:01 +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 Original-Received: via spool by 63861-submit@debbugs.gnu.org id=B63861.168632276917719 (code B ref 63861); Fri, 09 Jun 2023 15:00:01 +0000 Original-Received: (at 63861) by debbugs.gnu.org; 9 Jun 2023 14:59:29 +0000 Original-Received: from localhost ([127.0.0.1]:60030 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q7daK-0004bi-Sc for submit@debbugs.gnu.org; Fri, 09 Jun 2023 10:59:29 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:40428) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q7daI-0004bS-FX for 63861@debbugs.gnu.org; Fri, 09 Jun 2023 10:59:27 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id E410A80292; Fri, 9 Jun 2023 10:59:20 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id B0C0980262; Fri, 9 Jun 2023 10:59:19 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1686322759; bh=CRT6RgnC1gVjSMgbNLGzv0dbIG8bo64coTSaoY8dafU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=QY9JIRG4LHmasaETa1GrfMcib+V1wz788JdTKJD2A/USRATDBausUnXqaa6gtQJJ2 ZMzcf///ZNKcOl5mkpTVKgkg46EJ8m3whHSohfPxjSjrPS0a8MeffUdQ52MvJLfGr3 bRXSr0Y3uC39jRU9n3IzVCu6MWgZNiHAXI2sKM6gm10Icbq4vElomAtgaN0XzF1Sjp 1CuDZjirUpuI75y+ncKLxOFwbvUoIDH0ZfypXfRWT2q6K80SY1nNuhz0n0GO8pHbUE HDWRZ6lnmoRuniLeujEcr35egpX0OjaNjHWWKBX1cRWDWo40NKunkuh3XEpRsmRaQy 4OTJOJANRYSdw== Original-Received: from alfajor (unknown [45.44.229.252]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 88B501204E7; Fri, 9 Jun 2023 10:59:19 -0400 (EDT) In-Reply-To: <87cz25b9rw.fsf@gmail.com> (Visuwesh's message of "Fri, 09 Jun 2023 08:51:39 +0530") 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:263168 Archived-At: >>> BTW, how does this compare to the newly added `pp-emacs-lisp-code`? >> Very good question. I had completely missed that (and its `pp-use-max-width`). >> This points to a host of integration issues between my code and the >> existing code. I'll have to take a deeper look. > From what I remember, pp simply switches to use pp-emacs-lisp-code when > the relevant user option is set. Yup, similar to my patch, except my patch hooks into `pp-buffer`, i.e. a lower level which hence affects more uses. > The poor performance of pp-emacs-lisp-code made me wish > pp-use-max-width was only obeyed by user facing commands like > pp-eval-expression & friends. My tests yesterday suggest `pp-emacs-lisp-code` is simply too slow to be used except when we know beforehand that the sexp to be printed is small. And I can't think of a single piece of code where that's the case. I suspect part of the code can be improved to bring the computational complexity of the code closer to linear, but until someone does that, I think `pp-use-max-width` is just unusable. Instead we could/should provide ways for the user to interactively call a command to reformat something using `pp-emacs-lisp-code`. Or maybe change the code so `pp-emacs-lisp-code` is used only when the total printed size is below a certain threshold. >> My new code is expected to be slower than the "normal" pretty-printer, >> but barring performance bugs in `lisp-indent-line` (such as the one >> fixed by the patch I just sent to Thierry) it should be approximately >> a constant factor slower. >> AFAICT the performance of `pp-emacs-lisp-code` can be more problematic. > Hopefully, the constant factor is quite small. In my tests, 10x seems to be the "worst case slowdown" of `pp-region`. On some of the tests, it's actually faster, sometimes significantly so (presumably due to some non-linear complexity in some parts of `pp-buffer`). > pp-emacs-lisp-code took a lot of time to print my modest bookmark > alist (28 entries) and for the longest time I thought some other code > in Emacs has gone awry. AFAICT it suffers from a pretty bad complexity. > I haven't tested your pretty printer but pp-emacs-lisp-code could give > some really bizarre results for lisp data. I haven't seen "really bizarre results" with `pp-region` yet, but I wouldn't be surprised if that can happen: I've been playing with various pretty-printing alternatives over the years and they all seem to suffer from weird behaviors occasionally, except for those that insert too many line breaks. Stefan