From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Michal Nazarewicz Newsgroups: gmane.emacs.bugs Subject: bug#26079: 26.0.50; Performance regression in delete-trailing-whitespace Date: Tue, 14 Mar 2017 14:00:34 +0100 Organization: http://mina86.com/ Message-ID: References: <87d1dk7h25.fsf@users.sourceforge.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1489496482 17800 195.159.176.226 (14 Mar 2017 13:01:22 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 14 Mar 2017 13:01:22 +0000 (UTC) Cc: 26079@debbugs.gnu.org To: npostavs@users.sourceforge.net, Sho Takemori Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Mar 14 14:01:18 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cnm4f-00040c-Tg for geb-bug-gnu-emacs@m.gmane.org; Tue, 14 Mar 2017 14:01:14 +0100 Original-Received: from localhost ([::1]:58670 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnm4m-0003Yt-2n for geb-bug-gnu-emacs@m.gmane.org; Tue, 14 Mar 2017 09:01:20 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51144) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnm4Z-0003X9-9B for bug-gnu-emacs@gnu.org; Tue, 14 Mar 2017 09:01:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnm4U-0008MK-EJ for bug-gnu-emacs@gnu.org; Tue, 14 Mar 2017 09:01:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:56788) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cnm4U-0008M7-8k for bug-gnu-emacs@gnu.org; Tue, 14 Mar 2017 09:01:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cnm4U-0005j3-12 for bug-gnu-emacs@gnu.org; Tue, 14 Mar 2017 09:01:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michal Nazarewicz Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 14 Mar 2017 13:01:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 26079 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 26079-submit@debbugs.gnu.org id=B26079.148949644621980 (code B ref 26079); Tue, 14 Mar 2017 13:01:01 +0000 Original-Received: (at 26079) by debbugs.gnu.org; 14 Mar 2017 13:00:46 +0000 Original-Received: from localhost ([127.0.0.1]:54987 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cnm4D-0005iR-HH for submit@debbugs.gnu.org; Tue, 14 Mar 2017 09:00:45 -0400 Original-Received: from mail-wm0-f42.google.com ([74.125.82.42]:34865) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cnm4B-0005iC-6N for 26079@debbugs.gnu.org; Tue, 14 Mar 2017 09:00:44 -0400 Original-Received: by mail-wm0-f42.google.com with SMTP id v186so63350008wmd.0 for <26079@debbugs.gnu.org>; Tue, 14 Mar 2017 06:00:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:in-reply-to:organization:references:face :openpgp:date:message-id:mime-version:content-transfer-encoding; bh=+M+S16Hei7qe3u/7nHxllI1RHwP7Yvx4REd9pNJE0Vo=; b=LJpKKeFi3dyH57gmgYY5HONNAoS6AVE0MgdcXsNBdfVA861zgN4MIg/JOcbtD230yq 07AcFPIhCYvw3XaUXU668bdgNZOGtqdZ8xP/xEPDjYwjtf9vBnkTYt2K9JUYnv3OWIfB oYHHbuJzyKDKVMhasIw9iKK3v8U9fgkY21A523UHGsmmEBd9RU13VIbVMKSRSR3wCKP+ GKlspgKR+Vj5ZMAl0pRfaqRS4G6/GRIhn1Mk3fKxjmY5GeTHX5//V+X4Fc4lp9DaRe+J g69mvZGFIsNWnu04/YXVra/2O4x/3xY6kOj8zvGZPUQKMqXr7oSLkPkDFgvLdxsbq50+ JIeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:in-reply-to :organization:references:face:openpgp:date:message-id:mime-version :content-transfer-encoding; bh=+M+S16Hei7qe3u/7nHxllI1RHwP7Yvx4REd9pNJE0Vo=; b=qhQxOb0dvSU8RwOorOSMyqYR9icWLqbyzJwyZ9B5/TmSDRY+7QAqr/AEPkE8NfHcXl hH53NB3DPvB/UWA7oxiLpYILyTAKCADlkArg24tYed5Lcxo6lK4/wpfVXf69DjGgiZ4x Y8I/89PkPig6ObpuR725wIhXy3k4DgwWoTj7VfYfmo0vkzdYU4IMyVOO/NbNw3fdwFjC /9KHnHgA93hUBvmhSTH2kn39UBNbhHeo2Mc+4S+sWhEF4n3bxhUmLpWDGf+oQ7efSfec T46OcyG0IT1CUTmcZ05YBbEOTvSBDJpyr/obGJH+VgXpr1TP4xyQnislxf9dWl8b4syG lh/g== X-Gm-Message-State: AFeK/H07Y0NGcOoS/4Dx5vi1o1oFSUlvEy9c08ed44BDO5pTMqnuk583Xqm8BpW52T3lm4xz X-Received: by 10.28.28.69 with SMTP id c66mr15793119wmc.28.1489496436270; Tue, 14 Mar 2017 06:00:36 -0700 (PDT) Original-Received: from mpn-glaptop ([2620:0:105f:fd00:cc6a:9828:7609:20dd]) by smtp.gmail.com with ESMTPSA id g45sm29018553wrd.11.2017.03.14.06.00.35 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 14 Mar 2017 06:00:35 -0700 (PDT) In-Reply-To: <87d1dk7h25.fsf@users.sourceforge.net> Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAJFBMVEWbfGlUPDDHgE57V0jUupKjgIObY0PLrom9mH4dFRK4gmjPs41MxjOgAAACP0lEQVQ4T23Sv2vbQBQHcBk1xE6WyALX107VUEgmn6+ouUwpEQQ6uRjttkWP4CkBg2M0BQLBdPFZYPsyFYo7qEtKDQ7on+t7+nF2Ux8ahD587717OmNYrOvycHsZ+o2r051wHTHysAvGb8ygvgu4QWT0sCmkgZCIEnlV2X8BtyraazFGDuxhmKSQJMlwHQ7v5MHSNxmz78rfElwAa3ieVD9e+hBhjaPDDG6NgFo2f4wBMNIo5YmRtF0RyDgFjJjlMIWbnuM4x9MMfABGTlN4qgIQB4A1DEyA1BHWtfeWNUMwiVJKoqh97KrkOO+qzgluVYLvFCUKAX73nONeBr7BGMdM6Sg0kuep03VywLaIzRiVr+GAzKlpQIsAFnWAG2e6DT5WmWDiudZMIc6hYrMOmeMQK9WX0B+/RfjzL9DI7Y9/Iayn29Ci0r2i4f9gMimMSZLCDMalgQGU5hnUtqAN0OGvEmO1Wnl0C0wWSCEHnuHBqmygxdxA8oWXwbipoc1EoNR9DqOpBpOJrnr0criQab9ZT4LL+wI+K7GBQH30CrhUruilgP9DRTrhVWZCiAyILP+wiuLeCKGTD6r/nc8LOJcAwR6IBTUs+7CASw3QFZ0MdA2PI3zNziH4ZKVhXCRMBjeZ1DWMekKwDCASwExy+NQ86TaykaDAFHO4aP48y4 fIcDM5yOG8GcTLbOyp8A8azjJI93JFd1EA6yN8sSxMQJWoABqniRZVykYgRXErzrdqExAoUrRb0xfRp8p2A/4XmfilTtkDZ4cAAAAASUVORK5CYII= X-Face: -TR8(rDTHy/(xl?SfWd1|3:TTgDIatE^t'vop%*gVg[kn$t{EpK(P"VQ=~T2#ysNmJKN$"yTRLB4YQs$4{[.]Fc1)*O]3+XO^oXM>Q#b^ix, O)Zbn)q[y06$`e3?C)`CwR9y5riE=fv^X@x$y?D:XO6L&x4f-}}I4=VRNwiA^t1-ZrVK^07.Pi/57c_du'& OpenPGP: id=AC1F5F5CD41888F8CC8458582060401250751FF4; url=http://mina86.com/mina86.pub X-Hashcash: 1:20:170314:stakemorii@gmail.com::7GoLkyeSkhkYiNTT:000000000000000000000000000000000000000003Cc3 X-Hashcash: 1:20:170314:npostavs@users.sourceforge.net::BV/6gTn/T7NEa2Sp:00000000000000000000000000000004AMR X-Hashcash: 1:20:170314:26079@debbugs.gnu.org::2qyQidQDH/qVrDuC:00000000000000000000000000000000000000004BW4 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: 208.118.235.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" Xref: news.gmane.org gmane.emacs.bugs:130570 Archived-At: On Mon, Mar 13 2017, npostavs wrote: > tags 26079 confirmed > quit > > Sho Takemori writes: > >> Dear developers, >> >> delete-trailing-whitespace in Emacs 26 for large files is very slow. >> >> For example, it took about 1.6s for this file (https://raw.githubusercon= tent.com/stakemori/e8theta_degree3/master/results/wt18_17_5/wt18_17_5.org). >> But in Emacs 25, it took about 0.003s. >> A similar code to the following is used in delete-trailing-whitespace. A= nd it is slow for large files. >> >> (save-excursion >> (let ((end-marker nil)) >> (goto-char (point-min)) >> (with-syntax-table (make-syntax-table (syntax-table)) >> (modify-syntax-entry ?\f "_") >> (modify-syntax-entry ?\n "_") >> (re-search-forward "\\s-+$" end-marker t)))) > > It seems that this regex causes a lot of backtracking when \n is not > whitespace. It was introduced in [1: 7c6317a049]; restoring the > strategy from before seems make it fast again. Michal, do you think > that's the best way to fix this? I wish Emacs=E2=80=99 RE was O(n). :( Yeah, I think reverting my commit is the best course of action. > --- i/lisp/simple.el > +++ i/lisp/simple.el > @@ -632,12 +632,11 @@ delete-trailing-whitespace > (goto-char (or start (point-min))) > (with-syntax-table (make-syntax-table (syntax-table)) > ;; Don't delete formfeeds, even if they are considered whitesp= ace. > (modify-syntax-entry ?\f "_") > - ;; Treating \n as non-whitespace makes things easier. > - (modify-syntax-entry ?\n "_") > - (while (re-search-forward "\\s-+$" end-marker t) > - (let ((b (match-beginning 0)) (e (match-end 0))) > + (while (re-search-forward "\\s-$" end-marker t) > + (skip-syntax-backward "-" (line-beginning-position)) > + (let ((b (point)) (e (match-end 0))) > (when (region-modifiable-p b e) > (delete-region b e))))) > (if end > (set-marker end-marker nil) > > > 1: 2016-07-04 23:44:06 +0200 7c6317a0498b6690ea668909ac012cb45e6f809b > Simplify =E2=80=98delete-trailing-whitespace=E2=80=99 by not treating \= n as whitespace --=20 Best regards =E3=83=9F=E3=83=8F=E3=82=A6 =E2=80=9C=F0=9D=93=B6=F0=9D=93=B2=F0=9D=93=B7= =F0=9D=93=AA86=E2=80=9D =E3=83=8A=E3=82=B6=E3=83=AC=E3=83=B4=E3=82=A4=E3=83= =84 =C2=ABIf at first you don=E2=80=99t succeed, give up skydiving=C2=BB