unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Jean-Philippe Gravel <jpgravel@gmail.com>
To: 10580@debbugs.gnu.org
Subject: bug#10580: 24.0.92; gdb initialization takes more than one minute at 100
Date: Thu, 13 Dec 2012 23:14:59 -0500	[thread overview]
Message-ID: <CAB3yAohLmBk__dJfdPoKFhfs2NfT5eNEb87AnRjO3xxs+7MqKw@mail.gmail.com> (raw)
In-Reply-To: <CA++fsGFSoALDSsHstHY+OWrFpHgmvgwUs67QJkGidHebvkR03g@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2441 bytes --]

Hi guys,



I actually have a fix for this problem.



I use Emacs to debug a software of colossal size.  With Emacs 23, it used
to be possible to start gdb within a minute.  With Emacs 24, it takes more
than a couple of hour.  I never actually had the patience to wait for it to
finish.



As stated in previous posts, the command -file-list-exec-source-files is
the one triggering the bottleneck.  In my case, the reply is 5Mb long.



It turns out that the problem IS the parsing of the data stream coming from
GDB.  The function gud-gdbmi-marker-filter is home to a colossal
bottleneck.  You’ll find in there not only one, but 4 major algorithmic
problems.



The first thing that strikes the eye is the way it handles the fact that
there are several types of GDB replies possible.  Instead of parsing the
data stream linearly, accepting the GDB messages in the order of arrival,
it looks over the whole stream for the first type of message, then the
second, then the next.  Complexity: O(nm), where n is the size of the steam
and m is the number of message types.  Then, when finding a message
matching the type we look for, it is removed from the stream by cloning the
whole string, but padding the original location with spaces.  Complexity:
O(ni), where i is the number of messages.



To go on with the analysis, consider the following: my tests indicate that
gdbmi-marker-filter receives data by chunk of about 225 bytes.  Since I
receive 5Mb of data, gdbmi ingests about 22000 packets.  For every chunk of
data received, the incoming data is concatenated to a new string: O(nj),
where j is the number of packets.  Each time, the whole parsing described
above is restarted: O(nmj) (!!!).  Feed in a 5Mb data stream and you’ll get
a hung emacs!



I fixed the above by writing a proper parser reading the data stream in
O(n).  With my test-case, the parse time goes down from ‘too long to even
tell’, to about 3 seconds.  Not only does it fix the startup problem, but
it makes pretty much all other gud commands impressively faster.  With
emacs 23, it used to take almost a full second to do a single “gud-next” in
my software.  When enabling gud-tooltip-mode, it was becoming totally
unusable.  By removing the bottleneck in gud-gdbmi-marker-filter, the above
become instantaneous.



I just need to finalize a few things and I can send you a patch file.



Cheers!

[-- Attachment #2: Type: text/html, Size: 4847 bytes --]

  parent reply	other threads:[~2012-12-14  4:14 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-22 12:42 bug#10580: 24.0.92; gdb initialization takes more than one minute at 100% CPU Dov Grobgeld
2012-01-23  0:53 ` Glenn Morris
     [not found]   ` <CA++fsGG4YuTtb2VC9R+GRcPN5+JSaKpkb+uO3WAX0+VXmh8HDQ@mail.gmail.com>
2012-01-23  9:21     ` Glenn Morris
2012-01-25  0:37       ` Glenn Morris
2012-01-25  8:49         ` Dov Grobgeld
2012-01-25  9:39           ` Dov Grobgeld
2012-01-25 19:05             ` Glenn Morris
2012-04-30  5:33               ` Dov Grobgeld
2012-04-30  6:36                 ` Dov Grobgeld
2012-05-06  4:13                   ` Chong Yidong
2012-05-06  4:55                     ` Dov Grobgeld
2012-05-06  5:39                       ` Chong Yidong
2012-05-06  7:06                         ` Dov Grobgeld
2012-05-07  2:53                           ` Chong Yidong
2012-05-07  5:07                             ` Dov Grobgeld
2012-05-07  6:11                               ` Chong Yidong
2012-05-07  6:26                                 ` Chong Yidong
2012-05-08  5:33                                   ` Dov Grobgeld
2012-05-08  7:56                                     ` Dov Grobgeld
2012-05-08  8:28                                       ` Chong Yidong
2012-05-08 11:59                                         ` Dov Grobgeld
2012-05-08 16:25                                           ` Chong Yidong
2012-05-08 17:47                                             ` Eli Zaretskii
2012-05-08 21:07                                               ` Dov Grobgeld
2012-05-08 21:24                                                 ` Andreas Schwab
2012-05-08 21:30                                                   ` Dov Grobgeld
2012-05-09  7:47                                                     ` Andreas Schwab
2012-05-09  8:44                                                       ` Dov Grobgeld
2012-05-09 17:36                                                         ` Eli Zaretskii
2012-05-10  6:00                                                           ` Dov Grobgeld
2012-05-10 14:13                                                             ` Chong Yidong
2012-05-10 19:07                                                               ` Dov Grobgeld
2012-05-10 20:25                                                                 ` Stefan Monnier
2012-05-11  6:33                                                                 ` Chong Yidong
2012-05-11  8:29                                                                   ` Dov Grobgeld
2012-05-11  9:47                                                                     ` Eli Zaretskii
2012-05-11 13:27                                                                       ` Chong Yidong
2012-11-05 20:36                                                                         ` Dov Grobgeld
2012-11-05 20:46                                                                           ` Eli Zaretskii
2012-11-05 23:51                                                                             ` Stefan Monnier
2012-05-10 16:32                                                             ` Eli Zaretskii
2012-05-10 18:43                                                               ` Dov Grobgeld
2012-05-08 17:38                                           ` Eli Zaretskii
2012-12-14  4:14 ` Jean-Philippe Gravel [this message]
2012-12-18  4:45   ` bug#10580: 24.0.92; gdb initialization takes more than one minute at 100 Jean-Philippe Gravel
2012-12-21  4:01     ` Chong Yidong
2013-03-01  3:31       ` Jean-Philippe Gravel
2013-03-11 17:14         ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAB3yAohLmBk__dJfdPoKFhfs2NfT5eNEb87AnRjO3xxs+7MqKw@mail.gmail.com \
    --to=jpgravel@gmail.com \
    --cc=10580@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).