From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail
From: Gemini Lasswell <gazally@runbox.com>
Newsgroups: gmane.emacs.bugs
Subject: bug#36566: 27.0.50; debug is sometimes horribly slow
Date: Sat, 13 Jul 2019 17:02:19 -0700
Message-ID: <877e8llbzo.fsf@runbox.com>
References: <87r26yvb4r.fsf@web.de> <871ryy2l1t.fsf@gmail.com>
 <87r26xjyon.fsf@web.de>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226";
	logging-data="241285"; mail-complaints-to="usenet@blaine.gmane.org"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2.90 (gnu/linux)
Cc: 36566@debbugs.gnu.org, Noam Postavsky <npostavs@gmail.com>
To: Michael Heerdegen <michael_heerdegen@web.de>
Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jul 14 02:03:09 2019
Return-path: <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org>
Envelope-to: geb-bug-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([209.51.188.17])
	by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
	(Exim 4.89)
	(envelope-from <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org>)
	id 1hmRyu-0010ea-88
	for geb-bug-gnu-emacs@m.gmane.org; Sun, 14 Jul 2019 02:03:08 +0200
Original-Received: from localhost ([::1]:58462 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.86_2)
	(envelope-from <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org>)
	id 1hmRyt-0006Bc-27
	for geb-bug-gnu-emacs@m.gmane.org; Sat, 13 Jul 2019 20:03:07 -0400
Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59769)
 by lists.gnu.org with esmtp (Exim 4.86_2)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1hmRyp-0006A6-Tv
 for bug-gnu-emacs@gnu.org; Sat, 13 Jul 2019 20:03:04 -0400
Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1hmRyo-0004ui-SW
 for bug-gnu-emacs@gnu.org; Sat, 13 Jul 2019 20:03:03 -0400
Original-Received: from debbugs.gnu.org ([209.51.188.43]:34806)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
 (Exim 4.71) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1hmRyo-0004tm-0X
 for bug-gnu-emacs@gnu.org; Sat, 13 Jul 2019 20:03:02 -0400
Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1hmRyn-0004vG-QC
 for bug-gnu-emacs@gnu.org; Sat, 13 Jul 2019 20:03:01 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Gemini Lasswell <gazally@runbox.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@gnu.org
Resent-Date: Sun, 14 Jul 2019 00:03:01 +0000
Resent-Message-ID: <handler.36566.B36566.156306255518885@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 36566
X-GNU-PR-Package: emacs
Original-Received: via spool by 36566-submit@debbugs.gnu.org id=B36566.156306255518885
 (code B ref 36566); Sun, 14 Jul 2019 00:03:01 +0000
Original-Received: (at 36566) by debbugs.gnu.org; 14 Jul 2019 00:02:35 +0000
Original-Received: from localhost ([127.0.0.1]:43627 helo=debbugs.gnu.org)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
 id 1hmRyN-0004uX-0b
 for submit@debbugs.gnu.org; Sat, 13 Jul 2019 20:02:35 -0400
Original-Received: from aibo.runbox.com ([91.220.196.211]:48390)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <gazally@runbox.com>) id 1hmRyJ-0004uL-S4
 for 36566@debbugs.gnu.org; Sat, 13 Jul 2019 20:02:33 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=runbox.com; 
 s=rbselector1;
 h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:
 References:Subject:Cc:To:From;
 bh=hFqa7EHL09BXzAnV72R9dm1A73A4uLUGZ9SiAoNSqiw=; b=XNR5LmDrJglzWIVSAagPGLrR0i
 EqVnlxRMg+eON46lJVG8HPnCuPBkKnU3NrUfTle5du6MTyMD4fGV2E7ZgEsNrIQJxVl4vs/KumR0r
 j/yvmJx+HKdggpj8ofZAYq5uUlM4oJ98IcVZ2UFtT8aUdKnoXyir4q3UJvWZo/v+4GVeoIT8+5Lye
 lHIs06jSzm/aDUf+9owpoe5EJovnu7rtX0rCiLEZ80QqOiwSl8T6RefWUWIrjPb/J31cRMq0TtMTq
 d5GhqJQ0Xsc23tXKVFNV3srYfeDmRf0wOcEeqzCk2nK+7RgLhV2VdZYdmfvPhIJDme6wIS8Z8XoSO
 dtyCLs2Q==;
Original-Received: from [10.9.9.203] (helo=mailfront21.runbox)
 by mailtransmit03.runbox with esmtp (Exim 4.86_2)
 (envelope-from <gazally@runbox.com>)
 id 1hmRyH-00011L-B5; Sun, 14 Jul 2019 02:02:29 +0200
Original-Received: by mailfront21.runbox with esmtpsa (uid:179284 )
 (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1)
 id 1hmRyG-0007Ya-Ai; Sun, 14 Jul 2019 02:02:28 +0200
In-Reply-To: <87r26xjyon.fsf@web.de> (Michael Heerdegen's message of "Thu, 11
 Jul 2019 00:46:00 +0200")
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 209.51.188.43
X-BeenThere: bug-gnu-emacs@gnu.org
List-Id: "Bug reports for GNU Emacs,
 the Swiss army knife of text editors" <bug-gnu-emacs.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/bug-gnu-emacs>
List-Post: <mailto:bug-gnu-emacs@gnu.org>
List-Help: <mailto:bug-gnu-emacs-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=subscribe>
Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org
Original-Sender: "bug-gnu-emacs"
 <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org>
Xref: news.gmane.org gmane.emacs.bugs:162952
Archived-At: <http://permalink.gmane.org/gmane.emacs.bugs/162952>

Michael Heerdegen <michael_heerdegen@web.de> writes:

> With print-gemsym -> nil, the debugger needs approx. 2 seconds here to
> pop up, and with print-gemsym -> t, approx. 12.  So I wonder why this
> setting makes it that slow - I would expect a small time penalty, but
> such a big difference?

The C printing code builds hash tables to match gensyms to the numbers
they are printed with.  So it is building and discarding these hash
tables which causes the garbage collection and the slowdown.  Emacs 26's
backtrace printing is also significantly slower with print-gensym turned
on.

The reason master is so much slower than Emacs 26 is because of the
adaptive abbreviating I added to reduce problems with really long lines.
In Emacs 26 it's hard to debug things like magit or org-mode because
lines in the backtrace can easily get to be thousands or millions of
characters long and display gets really slow.  When I added
backtrace-mode, I gave it a target line length and a function which
starts with guesses at the appropriate values of print-length and
print-level, and which iteratively prints using those values, and if the
length of the printed representation is over the target, it reduces
print-length and print-level and tries again.  That reprinting, and
consequential repeated construction of gensym hash tables, is what's
making master slower than Emacs 26 in this case.

I remember when I was writing that function thinking that it was a
heuristic sort of algorithm and would likely need tweaking, so here we
are.

The easy fix for you for today is to set backtrace-line-length to 100 or
less, which will make the initial values of print-length and print-level
so low that little reprinting will be done.  Then use
backtrace-expand-ellipsis (bound to "."), with or without C-u, on the
lines where you want to see the full data structure.  And try "+" and
"-" if you haven't already.

I'll experiment with tweaking the heuristic to reduce the amount of
reprinting it does, and let you know what I come up with.

> BTW, extra points if the debugger provided commands/ a menu to tune such
> settings (like printing variables) live when using it.

There is such a command for print-circle (bound to "#") and it would be
easy to add one for print-gensym, although I could use a keybinding
suggestion.  backtrace-line-length is a defcustom.