From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: bug-reference-prog-mode slows down CC Mode's scrolling by ~7% Date: Mon, 6 Sep 2021 19:08:45 +0000 Message-ID: References: <835yvgwdxb.fsf@gnu.org> <8335qkwddv.fsf@gnu.org> <83wnnwuxkj.fsf@gnu.org> <838s0armbl.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1665"; mail-complaints-to="usenet@ciao.gmane.io" Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Sep 06 21:20:17 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mNKAD-0000IU-8X for ged-emacs-devel@m.gmane-mx.org; Mon, 06 Sep 2021 21:20:17 +0200 Original-Received: from localhost ([::1]:54838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNKAC-0008Ic-98 for ged-emacs-devel@m.gmane-mx.org; Mon, 06 Sep 2021 15:20:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42692) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNJzA-0007Gl-G0 for emacs-devel@gnu.org; Mon, 06 Sep 2021 15:08:52 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:41813 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.90_1) (envelope-from ) id 1mNJz6-0003Fa-Bb for emacs-devel@gnu.org; Mon, 06 Sep 2021 15:08:52 -0400 Original-Received: (qmail 87388 invoked by uid 3782); 6 Sep 2021 19:08:46 -0000 Original-Received: from acm.muc.de (p4fe15c0e.dip0.t-ipconnect.de [79.225.92.14]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Mon, 06 Sep 2021 21:08:45 +0200 Original-Received: (qmail 8414 invoked by uid 1000); 6 Sep 2021 19:08:45 -0000 Content-Disposition: inline In-Reply-To: <838s0armbl.fsf@gnu.org> X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de Received-SPF: pass client-ip=193.149.48.1; envelope-from=acm@muc.de; helo=mail.muc.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:274168 Archived-At: Hello, Eli. On Mon, Sep 06, 2021 at 14:10:54 +0300, Eli Zaretskii wrote: > > Date: Mon, 6 Sep 2021 10:46:48 +0000 > > Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org > > From: Alan Mackenzie > > I think the optimal size for jit-lock-chunk-size is a little over how > > much text fits in a window. That way, an entire window can be fontified > > in a single chunk, minimising overhead. However, much more than that, > > and the fontification is less JIT, more like fontifying large chunks of > > a buffer just in case. > > So, I propose a default value of 2000. Approximately 1700 characters of > > xdisp.c fit into a default sized GUI window. > Not here. I only get 1300. Sorry. Slip between brain and keyboard. > In any case, can we please perform the single-windowful scroll > benchmark before making the decision? Doing this stuff from intuition > is known to be a bad idea. >From another post, you wrote: >>> To see the "waste" in single-windowful scrolls, we need a suitable >>> benchmark, which measures the time of each scroll separately. It >>> would probably make sense to make it generate a random value of >>> point, then measure the time it takes to go there and display. So I hacked together a quick benchmark chunk-size-benchmark, which takes a single argument, the jit-lock-chunk-size, and then in the current window and buffer moves successively to 10%, 20%, 30%, ...., 90% through the buffer and waits for fontification. The average of those ten values is output to the *Messages* buffer. Then I wrote a variation, which jumps to a 10x% position in the buffer, waits for fontification, then scrolls forward a screen and waits again for fontification. The average value is, again, printed out. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defmacro time-it (&rest forms) "Time the running of a sequence of forms using `float-time'. Call like this: \"M-: (time-it (foo ...) (bar ...) ...)\"." `(let ((start (float-time))) ,@forms (- (float-time) start))) (defun chunk-size-benchmark (chunk-size) (interactive "p") (if (< chunk-size 100) (error "chunk-size, %s, is less than 100" chunk-size)) (widen) (let ((jit-lock-chunk-size chunk-size) (buf-size (point-max)) this-time (total 0) ) (dolist (i '(0 1 2 3 4 5 6 7 8 9)) (font-lock-flush) (setq this-time (time-it (goto-char (1+ (/ (* i buf-size) 10))) (sit-for 0))) (setq total (+ total this-time))) (message "Average time for chunk-size %s is %s" chunk-size (/ total 10)))) (defun chunk-size-benchmark-2 (chunk-size) (interactive "p") (if (< chunk-size 100) (error "chunk-size, %s, is less than 100" chunk-size)) (widen) (let ((jit-lock-chunk-size chunk-size) (buf-size (point-max)) this-time (total 0) ) (dolist (i '(0 1 2 3 4 5 6 7 8 9)) (font-lock-flush) (setq this-time (time-it (goto-char (1+ (/ (* i buf-size) 10))) (sit-for 0) (scroll-up) (sit-for 0))) (setq total (+ total this-time))) (message "Average time for two chunk-size %s is %s" chunk-size (/ total 10)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; I got these timings, using xdisp.c each time: (i) On a 65 line window on a Linux console tty: Average time for chunk-size 500 is 0.09474895000457764 Average time for chunk-size 1000 is 0.08993968963623047 Average time for chunk-size 1500 is 0.07838799953460693 Average time for chunk-size 2000 is 0.0901902437210083 Average time for chunk-size 2500 is 0.09380950927734374 Average time for chunk-size 3000 is 0.09139835834503174 Average time for chunk-size 3500 is 0.09265313148498536 Average time for chunk-size 4000 is 0.09945495128631592 Average time for two chunk-size 500 is 0.14148397445678712 Average time for two chunk-size 1000 is 0.11814579963684083 Average time for two chunk-size 1500 is 0.11486186981201171 Average time for two chunk-size 2000 is 0.12313232421875 Average time for two chunk-size 2500 is 0.12045748233795166 Average time for two chunk-size 3000 is 0.1140979528427124 Average time for two chunk-size 3500 is 0.10788719654083252 Average time for two chunk-size 4000 is 0.11099658012390137 (ii) On a 34 line window (default size) in X Windows: Average time for chunk-size 500 is 0.06480436325073242 Average time for chunk-size 1000 is 0.06025857925415039 Average time for chunk-size 1500 is 0.06389858722686767 Average time for chunk-size 2000 is 0.06813716888427734 Average time for chunk-size 2500 is 0.07740669250488282 Average time for chunk-size 3000 is 0.0859900712966919 Average time for chunk-size 3500 is 0.09434397220611572 Average time for chunk-size 4000 is 0.10622837543487548 Average time for two chunk-size 500 is 0.09408855438232422 Average time for two chunk-size 1000 is 0.08264987468719483 Average time for two chunk-size 1500 is 0.08883922100067139 Average time for two chunk-size 2000 is 0.07863264083862305 Average time for two chunk-size 2500 is 0.08350887298583984 Average time for two chunk-size 3000 is 0.08896465301513672 Average time for two chunk-size 3500 is 0.09870367050170899 Average time for two chunk-size 4000 is 0.10917885303497314 (iii) On a 54 line window in X Windows: Average time for chunk-size 500 is 0.11301305294036865 Average time for chunk-size 1000 is 0.10326454639434815 Average time for chunk-size 1500 is 0.10011684894561768 Average time for chunk-size 2000 is 0.10956480503082275 Average time for chunk-size 2500 is 0.11465866565704345 Average time for chunk-size 3000 is 0.12143938541412354 Average time for chunk-size 3500 is 0.13569414615631104 Average time for chunk-size 4000 is 0.15041179656982423 Average time for two chunk-size 500 is 0.16088194847106935 Average time for two chunk-size 1000 is 0.14736626148223878 Average time for two chunk-size 1500 is 0.13186230659484863 Average time for two chunk-size 2000 is 0.14865143299102784 Average time for two chunk-size 2500 is 0.13905446529388427 Average time for two chunk-size 3000 is 0.13570570945739746 Average time for two chunk-size 3500 is 0.14243290424346924 Average time for two chunk-size 4000 is 0.15591373443603515 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; So, I would reason as follows: (i) 500 bytes is too small. (ii) We should be more concerned about the timings on larger windows, if we are concerned about redisplay times. 0.1s (for a 54 line window) is appreciably greater than 0.06s (a 34 line window), which is on the point of seeming instantaneous. (iii) The two chunk-size time on 54 lines suggests an optimum of 1500, which is supported by the corresponding times on the tty. (iv) 1500 is not far from optimal on 34 lines single chunk, though not so for the two chunk time. (It is notable that redisplay is quite a bit slower in X at 54 lines than on a Linux console at 65 lines.) So, based on these timings, I would suggest a new jit-lock-chunk-size of 1500. -- Alan Mackenzie (Nuremberg, Germany).