From: Michal Nazarewicz <mina86@mina86.com>
To: npostavs@users.sourceforge.net, Sho Takemori <stakemorii@gmail.com>
Cc: 26079@debbugs.gnu.org
Subject: bug#26079: 26.0.50; Performance regression in delete-trailing-whitespace
Date: Tue, 14 Mar 2017 14:00:34 +0100 [thread overview]
Message-ID: <xa1ty3w8j9n1.fsf@mina86.com> (raw)
In-Reply-To: <87d1dk7h25.fsf@users.sourceforge.net>
On Mon, Mar 13 2017, npostavs wrote:
> tags 26079 confirmed
> quit
>
> Sho Takemori <stakemorii@gmail.com> 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.githubusercontent.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. And 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’ 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 whitespace.
> (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 ‘delete-trailing-whitespace’ by not treating \n as whitespace
--
Best regards
ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴイツ
«If at first you don’t succeed, give up skydiving»
next prev parent reply other threads:[~2017-03-14 13:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-13 2:13 bug#26079: 26.0.50; Performance regression in delete-trailing-whitespace Sho Takemori
2017-03-14 2:01 ` npostavs
2017-03-14 13:00 ` Michal Nazarewicz [this message]
2017-03-15 2:36 ` npostavs
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=xa1ty3w8j9n1.fsf@mina86.com \
--to=mina86@mina86.com \
--cc=26079@debbugs.gnu.org \
--cc=npostavs@users.sourceforge.net \
--cc=stakemorii@gmail.com \
/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).