From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: An idea: combine-change-calls Date: Sun, 25 Mar 2018 19:14:24 +0000 Message-ID: <20180325191424.GE6292@ACM> References: <20180324135024.GA6319@ACM> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1522006340 13892 195.159.176.226 (25 Mar 2018 19:32:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 25 Mar 2018 19:32:20 +0000 (UTC) User-Agent: Mutt/1.7.2 (2016-11-26) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Mar 25 21:32:16 2018 Return-path: Envelope-to: ged-emacs-devel@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 1f0BNI-0003Vu-5n for ged-emacs-devel@m.gmane.org; Sun, 25 Mar 2018 21:32:16 +0200 Original-Received: from localhost ([::1]:52339 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0BPL-00012K-Ab for ged-emacs-devel@m.gmane.org; Sun, 25 Mar 2018 15:34:23 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0BOa-00011w-8Y for emacs-devel@gnu.org; Sun, 25 Mar 2018 15:33:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f0BOV-0004oS-4u for emacs-devel@gnu.org; Sun, 25 Mar 2018 15:33:36 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:25586 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1f0BOU-0004nf-P9 for emacs-devel@gnu.org; Sun, 25 Mar 2018 15:33:31 -0400 Original-Received: (qmail 31563 invoked by uid 3782); 25 Mar 2018 19:33:29 -0000 Original-Received: from acm.muc.de (p5B14605B.dip0.t-ipconnect.de [91.20.96.91]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sun, 25 Mar 2018 21:33:27 +0200 Original-Received: (qmail 8904 invoked by uid 1000); 25 Mar 2018 19:14:24 -0000 Content-Disposition: inline In-Reply-To: X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 193.149.48.1 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:224015 Archived-At: Hello, Stefan. On Sat, Mar 24, 2018 at 18:18:05 -0400, Stefan Monnier wrote: > > The motivation is bug #30735, > [ Not surprised: I told you CC-mode's change-functions are too costly, > because they presumes that before&after-change-functions are called at > a "human" rate (comparable to pre/post-command-hook). > before&after-change-functions should be handled a bit like POSIX > signals: do as little work as possible there, and handle them > later elsewhere. `comment-region` is not the only command that can > make many small changes. ] Yes, acknowledged. > > What do people think? > I actually do like the idea of combining such things, tho it's risky: > e.g. if the code within combine-change-calls uses syntax-ppss it might > get wrong results since syntax-ppss-flush-cache is triggered via > before-change-functions. The same problem would affect > syntax-propertize, of course. OK. That could be a problem in general. I've actually got a working implementation going. It is this: (defmacro combine-change-calls (beg end &rest form) `(if (not inhibit-modification-hooks) (let* ((-beg- ,beg) (-end- ,end) (end-marker (copy-marker -end-))) (run-hook-with-args 'before-change-functions beg end) (let ((inhibit-modification-hooks t)) ,@form) (run-hook-with-args 'after-change-functions beg (marker-position end-marker) (- -end- -beg-))) ,@form)) With it used in newcomment.el, C-c C-c and C-u C-c C-c on large portions of CC Mode files go fast enough. > Grepping for `add-hook.*before-change-functions` indicates that similar > problem could appear elsewhere. Not sure what to do about it other than > to say "don't over-use it, it might bite you". > Also we'd need such a system to check that the bounds > are indeed obeyed. > One more thing: with the sample code you showed, undoing will still be > just as slow since it won't benefit from combine-change-calls. Yes, this is indeed the case. > Maybe combine-change-calls should also combine all those changes on the > undo-list into a big "delete+insert" (of course, it could also try and > keep the undo granularity but mark those undo entries so that they're > undone within their own combine-change-calls). :-) Either of those would be quite a project, but possibly worth doing. Thanks for the idea. > Stefan -- Alan Mackenzie (Nuremberg, Germany).