bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#36566: 27.0.50; debug is sometimes horribly slow


From: Gemini Lasswell
Subject: bug#36566: 27.0.50; debug is sometimes horribly slow
Date: Wed, 31 Jul 2019 17:53:17 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2.90 (gnu/linux)

Gemini Lasswell <gazally@runbox.com> writes:

> 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.

That statement turned out to be true, however once I improved the
adaptive abbreviating algorithm it became apparent to me that backtrace
printing was creating an excessive amount of garbage in both Emacs 26
and 27 when either print-circle or print-gensym was set.

As part of my investigating process I made a patch which added a
hash-tables-consed variable along the lines of strings-consed et al,
which I incremented in Fmake_hash_table to count the number of hash
tables created, and got the following interesting result:

(let ((print-gensym t))
  (list hash-tables-consed (princ "hello") hash-tables-consed))
=>
hello
(814064 "hello" 814065)

This is relevant to backtrace printing because backtrace printing uses
cl-prin1, which prints Lisp data structures using

(princ "(" stream)

to print the parentheses, which was making for a lot of created and
destroyed hash tables whenever print-circle or print-gensym was set.

The third patch attached below fixes that by adding a macro to
cl-print.el to wrap the printing of all the simple things with
let-bindings of print-circle and print-gensym to nil.

Patch #2 improves cl-print-to-string-with-limit's adaptive fitting of a
printed representation into a given line length by making it reduce
print-level and print-length more rapidly when the result of a test
printing is very long.

Patch #1 improves the backtrace-mode UI by adding a command to toggle
print-gensym, and puts both that and its print-circle toggle command on
the menu, and adds an echo area message to both to let you know what
they did.

Here's how long Michael's use case takes to render the backtrace
buffer on my machine, with print-gensym non-nil, in various versions of
Emacs:

Emacs 26.2: 4.1s
Emacs 27, before patches: 9.4s
Emacs 27, with patch #2: 5.6s
Emacs 27, with patches #2 and #3: 1.2s.

Patch #3 has the advantage of being straightforward logically and not
breaking anything which doesn't use cl-prin1, but it undoubtedly also
slows down cl-prin1 in the probably more common case that print-gensym
and print-circle are both nil.  There are other ways to fix this, such
as by adding a new entry point in print.c for printing simple strings,
or by modifying the logic in print_preprocess to not create a hash table
if the top-level object is a string with no properties.  I'm not sure
what the best choice is here, so let me know what you think.

Attachment: 0001-Improve-print-output-options-commands-in-backtrace-m.patch
Description: Patch #1

Attachment: 0002-Improve-performance-of-backtrace-printing-bug-36566.patch
Description: Patch #2

Attachment: 0003-Fix-excessive-hash-table-creation-in-cl-prin1-bug-36.patch
Description: Patch #3


reply via email to

[Prev in Thread] Current Thread [Next in Thread]