From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.bugs Subject: bug#15295: python mode slow to unusable Date: Sat, 26 Oct 2013 13:39:21 +0200 Message-ID: <87fvrofehi.fsf@web.de> References: <522A7797.4020903@codefu.org> <87y55gie7r.fsf@halogen-dg.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1382787619 1737 80.91.229.3 (26 Oct 2013 11:40:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 26 Oct 2013 11:40:19 +0000 (UTC) Cc: 15295@debbugs.gnu.org To: Alex V. Koval Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Oct 26 13:40:22 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Va2E7-0004h4-3F for geb-bug-gnu-emacs@m.gmane.org; Sat, 26 Oct 2013 13:40:19 +0200 Original-Received: from localhost ([::1]:34301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Va2E6-0000tu-Kn for geb-bug-gnu-emacs@m.gmane.org; Sat, 26 Oct 2013 07:40:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48555) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Va2Dx-0000tb-Im for bug-gnu-emacs@gnu.org; Sat, 26 Oct 2013 07:40:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Va2Dr-0005NZ-Mg for bug-gnu-emacs@gnu.org; Sat, 26 Oct 2013 07:40:09 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:59071) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Va2Dr-0005Lk-K7 for bug-gnu-emacs@gnu.org; Sat, 26 Oct 2013 07:40:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Va2Dq-00024A-9l for bug-gnu-emacs@gnu.org; Sat, 26 Oct 2013 07:40:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michael Heerdegen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 26 Oct 2013 11:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 15295 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 15295-submit@debbugs.gnu.org id=B15295.13827875767904 (code B ref 15295); Sat, 26 Oct 2013 11:40:02 +0000 Original-Received: (at 15295) by debbugs.gnu.org; 26 Oct 2013 11:39:36 +0000 Original-Received: from localhost ([127.0.0.1]:44857 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Va2DO-00023N-74 for submit@debbugs.gnu.org; Sat, 26 Oct 2013 07:39:34 -0400 Original-Received: from mout.web.de ([212.227.15.4]:61959) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Va2DK-000235-Ni for 15295@debbugs.gnu.org; Sat, 26 Oct 2013 07:39:31 -0400 Original-Received: from drachen.dragon ([90.187.153.26]) by smtp.web.de (mrweb001) with ESMTPA (Nemesis) id 0MKr7w-1Va2DB42nw-0005db for <15295@debbugs.gnu.org>; Sat, 26 Oct 2013 13:39:24 +0200 In-Reply-To: <87y55gie7r.fsf@halogen-dg.com> (Alex V. Koval's message of "Sat, 26 Oct 2013 12:16:56 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-Provags-ID: V03:K0:MGbeD1WRgOneLlY3k5rbG32u+4dgaVEa/2hu2vjxbEE6/mnrkuE sbHVZn2nVsAbZWhsBfVx1AII6DQ+v/h+p8Elq0z22mksbZ31Xu71LUqPvaj1oF/UJurHRro e59UE+kXbKK7xeFZsi9KrAT1lnG7Kc2GTFz6EM/4NuoZaABmS29b2dqAaQLTGUAwh1mljNY UnRVGCV9FxWUlYnQUPGtA== X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 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.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:79671 Archived-At: Alex V. Koval writes: > For me this is happen as well. Emacs, starting from version 24.3 became > so slow in Python mode that I had to tell all developers at our company > to use version 24.2 until I sorted this out. > > Sit today and started trying various emacs versions, and calling > different functions. The suggested test case from original author above, > runs with this benchmark: > > (7.3956507 53 1.8788885930000063) I profiled a bit, and, at least in this example, these two functions seem to be extremely inefficient in combination: (defun python-nav-beginning-of-statement () "Move to start of current statement." (interactive "^") (while (and (or (back-to-indentation) t) (not (bobp)) (when (or (save-excursion (forward-line -1) (python-info-line-ends-backslash-p)) (python-syntax-context 'string) (python-syntax-context 'paren)) (forward-line -1)))) (point-marker)) (defun python-info-line-ends-backslash-p (&optional line-number) "Return non-nil if current line ends with backslash. With optional argument LINE-NUMBER, check that line instead." (save-excursion (save-restriction (widen) (when line-number (python-util-goto-line line-number)) (while (and (not (eobp)) (goto-char (line-end-position)) (python-syntax-context 'paren) (not (equal (char-before (point)) ?\\))) (forward-line 1)) (when (equal (char-before) ?\\) (point-marker))))) They consume most of the time used. While the first function goes backward, the second goes forward to the end in every loop cycle. This makes the thing O(n^2), with n being the number of lines of the expression. I don't know Python, so I can't make any suggestions. Who can? At least, changing the order of `or' expressions in `python-nav-beginning-of-statement' seems to help in the example case: (defun python-nav-beginning-of-statement () "Move to start of current statement." (interactive "^") (while (and (or (back-to-indentation) t) (not (bobp)) (when (or (python-syntax-context 'string) (python-syntax-context 'paren) (save-excursion (forward-line -1) (python-info-line-ends-backslash-p))) (forward-line -1)))) (point-marker)) It's also not efficient how often `syntax-ppss' is called all the time. Regards, Michael.