From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kelly Dean Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] (Updated) Run hook when variable is set Date: Fri, 06 Feb 2015 09:55:42 +0000 Message-ID: <2JD0ndAte7Xgh4tgCiY96gQXIIlu7In5zHgMzh0d8FE@local> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1423216639 24920 80.91.229.3 (6 Feb 2015 09:57:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 6 Feb 2015 09:57:19 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Feb 06 10:57:06 2015 Return-path: Envelope-to: ged-emacs-devel@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 1YJfes-0006LO-4z for ged-emacs-devel@m.gmane.org; Fri, 06 Feb 2015 10:57:06 +0100 Original-Received: from localhost ([::1]:47413 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJfer-000748-Fd for ged-emacs-devel@m.gmane.org; Fri, 06 Feb 2015 04:57:05 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34102) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJfeo-00073k-5q for emacs-devel@gnu.org; Fri, 06 Feb 2015 04:57:03 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YJfei-0001zX-9q for emacs-devel@gnu.org; Fri, 06 Feb 2015 04:57:02 -0500 Original-Received: from relay6-d.mail.gandi.net ([2001:4b98:c:538::198]:49411) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJfeh-0001yk-N3 for emacs-devel@gnu.org; Fri, 06 Feb 2015 04:56:56 -0500 Original-Received: from mfilter30-d.gandi.net (mfilter30-d.gandi.net [217.70.178.161]) by relay6-d.mail.gandi.net (Postfix) with ESMTP id 7939DFB8B9; Fri, 6 Feb 2015 10:56:54 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter30-d.gandi.net Original-Received: from relay6-d.mail.gandi.net ([217.70.183.198]) by mfilter30-d.gandi.net (mfilter30-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id emtanqf9Lcmk; Fri, 6 Feb 2015 10:56:53 +0100 (CET) X-Originating-IP: 66.220.3.179 Original-Received: from localhost (gm179.geneticmail.com [66.220.3.179]) (Authenticated sender: kelly@prtime.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 8F901FB8DB; Fri, 6 Feb 2015 10:56:51 +0100 (CET) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4b98:c:538::198 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:182511 Archived-At: As a followup to my previous message, here are some benchmarks to test th= e worst-case performance impact of the varhook-single patch. This is with= out any changes to the patch; the =C2=ABhooked=C2=BB bit is still separat= e from =C2=ABconstant=C2=BB, so try_run_varhook is executed every time a = non-lexical variable is set. This is on an Intel Core 2 (more than 8 years old, so not taking advantag= e of any recent CPU optimizations, but it does have a branch predictor, w= hich is an ancient feature). Emacs is compiled with its default optimizat= ion settings, with and without the patch. Note, to compile 24.4 with the patch, you have to add to the top of data.= c the line: static Lisp_Object Qvarhook, Qglobal, Qbuf_local, Qdyn_local, Qdyn_bind, = Qdyn_unbind, Qinvalid; Do emacs -Q, then: (require 'cl) (setq x 0) (defun test () (benchmark-run-compiled 100000 (incf x))) With Emacs 24.4, without the patch: (test) =E2=86=92 (0.009720718000000003 0 0.0) (test) =E2=86=92 (0.007469938999999995 0 0.0) (test) =E2=86=92 (0.007450257000000002 0 0.0) With the patch: (test) =E2=86=92 (0.006218317000000001 0 0.0) (test) =E2=86=92 (0.0055950570000000005 0 0.0) (test) =E2=86=92 (0.005777339000000006 0 0.0) IOW, varhook miraculously makes Emacs faster! ;-) Ok, another couple test runs: Without the patch: (test) =E2=86=92 (0.006397249999999993 0 0.0) (test) =E2=86=92 (0.006253384000000001 0 0.0) (test) =E2=86=92 (0.006264767000000004 0 0.0) With the patch: (test) =E2=86=92 (0.007369438000000006 0 0.0) (test) =E2=86=92 (0.006640647999999999 0 0.0) (test) =E2=86=92 (0.007056691999999989 0 0.0) With multiple runs, the difference is below the accuracy of measurement. Continuing onward with the patch: (hook 'x) ; But =C2=ABvarhook=C2=BB is still nil (i.e. there's no handler= function) ;; Now, run_varhook will be called each time x is incremented. (test) =E2=86=92 (0.04964255199999999 0 0.0) (test) =E2=86=92 (0.046831024 0 0.0) (test) =E2=86=92 (0.047073512 0 0.0) (add-hook 'varhook (lambda (_sym _env _val) nil)) (test) =E2=86=92 (0.07824081199999999 0 0.0) (test) =E2=86=92 (0.07892686900000001 0 0.0) (test) =E2=86=92 (0.07999398 0 0.0) (unhook 'x) (test) =E2=86=92 (0.00680763899999999 0 0.0) (test) =E2=86=92 (0.005905495999999996 0 0.0) (test) =E2=86=92 (0.006095260000000005 0 0.0) All as expected. After unhooking, the results are again indistinguishable= from the results of Emacs without the patch. Another test: (require 'cl) (defun test1 () (setq x 0) (benchmark-run-compiled (do () ((> x 100000)) (incf x)))) Without the patch: (test1) =E2=86=92 (0.010726432 0 0.0) (test1) =E2=86=92 (0.010739914 0 0.0) (test1) =E2=86=92 (0.010754511 0 0.0) With the patch: (test1) =E2=86=92 (0.011321344 0 0.0) (test1) =E2=86=92 (0.011568507 0 0.0) (test1) =E2=86=92 (0.011352074 0 0.0) Without the patch: (test1) =E2=86=92 (0.011268476 0 0.0) (test1) =E2=86=92 (0.011142896 0 0.0) (test1) =E2=86=92 (0.011574237 0 0.0) With the patch: (test1) =E2=86=92 (0.011327352 0 0.0) (test1) =E2=86=92 (0.011323509 0 0.0) (test1) =E2=86=92 (0.011337811 0 0.0) The difference is again below the accuracy of measurement. Based on these results, I recommend against putting the =C2=ABhooked=C2=BB= bit into the =C2=ABconstant=C2=BB field. It wouldn't accomplish anything= , and it would reduce the clarity of the source code.