From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#74357: c-mode: Some syntactic constructs cause unreasonable typing lag Date: Fri, 15 Nov 2024 16:25:39 +0200 Message-ID: <86ed3cinfg.fsf@gnu.org> References: <86v7wphrmi.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12442"; mail-complaints-to="usenet@ciao.gmane.io" Cc: acm@muc.de, 74357@debbugs.gnu.org To: =?UTF-8?Q?Bj=C3=B6rn?= Lindqvist Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Nov 15 15:26:24 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1tBxHD-00030O-Co for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 15 Nov 2024 15:26:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBxGv-0008RG-0l; Fri, 15 Nov 2024 09:26:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tBxGs-0008Of-L4 for bug-gnu-emacs@gnu.org; Fri, 15 Nov 2024 09:26:02 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tBxGs-000131-CI for bug-gnu-emacs@gnu.org; Fri, 15 Nov 2024 09:26:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-version:References:In-Reply-To:From:Date:To:Subject; bh=m2psn7SKKRt273ODVRTa/hq7xOdNfaNpC6IDSWlzBGo=; b=HCW+7DXol2Ie6jeREPhWD1HDslkEv3Ng1twlgiw3FFPk+yeJMZndjBRZcMnXR9dreCELUbDuR4KGxY5k8dWkgwrd7+DTYpGzTM15aKFFEx4P/mr+Q5yQa2Z0+4tXGAy7WiWbtIHCcjLZlLtEEEdqXZ1ydKjv4V7JdXzn1FFlW5ofRq5AH57Bxtvq1+ab+mWFzM8nNi6CGg0bs7AwmVoqf2Us9NivVqfi4v4wskAMS8tl2PXG+4fx2lAPTqwdpJPhZ48FOAp/UGSMCAsSiXUklz4Cl3VZ4cjL9pLvpkQ0gVq/uaQ6HZdEB/zZX3JQgGyKfTRlI14BSvwlpryh0mxSiA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tBxGs-0007Tt-1L for bug-gnu-emacs@gnu.org; Fri, 15 Nov 2024 09:26:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 15 Nov 2024 14:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74357 X-GNU-PR-Package: emacs Original-Received: via spool by 74357-submit@debbugs.gnu.org id=B74357.173168075328741 (code B ref 74357); Fri, 15 Nov 2024 14:26:01 +0000 Original-Received: (at 74357) by debbugs.gnu.org; 15 Nov 2024 14:25:53 +0000 Original-Received: from localhost ([127.0.0.1]:49085 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tBxGi-0007TT-62 for submit@debbugs.gnu.org; Fri, 15 Nov 2024 09:25:53 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:36468) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tBxGe-0007TF-Pp for 74357@debbugs.gnu.org; Fri, 15 Nov 2024 09:25:49 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tBxGY-00010U-Pz; Fri, 15 Nov 2024 09:25:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=m2psn7SKKRt273ODVRTa/hq7xOdNfaNpC6IDSWlzBGo=; b=KCG6Ci9O2TMgzkSnlzdP pxz3uY3u8J9TIor4HZHGHXKvMpFPiYw0un7c6G4W3Jj3o2wSbtPHxAPaCqAnhE9XMlfI9OS5G1anm laG15Fn4SyegT4Iv9dT68cHw7UDeJpz7NCXLIa1ST9//cPWYOveWFD/u3HDNgcRY3biwehCwQCxUs eNOMutByomIwsy0ftqE7U2+cQ8Tu775KIKt2c2EM17sNAt/OfGi3D2dhGrZ13SUxS4WQtyHP3q+DV 5KRdPBqW47n4nM2ysHjQMPb8xO8+aMEveMS1xYrE5TRbpgTgzNc5Zc8GjEhAhqE7DnbR1imms4row 1p3mrj0orKEHCA==; In-Reply-To: (message from =?UTF-8?Q?Bj=C3=B6rn?= Lindqvist on Fri, 15 Nov 2024 15:08:09 +0100) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:295394 Archived-At: > From: Björn Lindqvist > Date: Fri, 15 Nov 2024 15:08:09 +0100 > Cc: Alan Mackenzie , 74357@debbugs.gnu.org > > > I've wrapped the snippet with 50 foo, and I still don't see any > > significant lags. > > > > Does it matter where you type, for reproducing the lag? > > > > Also, can you run this under a profiler (M-x profiler-start) and then > > show the full expanded profile produced by "M-x profiler-report" after > > several tens of seconds of typing with the lag? > > > > Adding Alan to the discussion. > > Hello Eli, thanks for the swift reply. > > > I've created a much larger example so you can see what I mean with > "wrapping foo in foo": > > https://gist.github.com/bjourne/8f705c5879aa966accf354008623f6bb > > Open file in c-mode, Go to line 328, place the cursor on "y" in "dy_dim" > and press and hold "y". Unless you have a supercomputer the lag will be > really apparent. Disable Global Font-lock mode and repeat the exercise. > Lag will be gone. Lag is worse if I use non-jitted Emacs, but really > apparent in jitted Emacs too. Lag goes away if I use c-ts-mode instead > of c-mode. Yes, I see the lag now, thanks; the profile is below. I'll let Alan look into this and see how this can be improved. > I want to emphasize that lag is present in normal code too, but easier > to detect in these specially crafted samples. Can you tell where in real life do you see such deeply-nested braces in C source files? Here's the profile I collected: 622 60% - redisplay_internal (C function) 615 59% - jit-lock-function 615 59% - jit-lock-fontify-now 614 59% - jit-lock--run-functions 614 59% - run-hook-wrapped 614 59% - # 614 59% - font-lock-fontify-region 614 59% - c-font-lock-fontify-region 582 56% - font-lock-default-fontify-region 581 56% - font-lock-fontify-keywords-region 323 31% - c-font-lock-cut-off-declarators 302 29% - c-get-fontification-context 301 29% - c-inside-bracelist-p 221 21% - c-looking-at-or-maybe-in-bracelist 154 14% - c-laomib-loop 69 6% - c-backward-sws 23 2% - c-beginning-of-macro 5 0% - back-to-indentation 2 0% skip-syntax-forward 1 0% line-end-position 1 0% backward-prefix-chars 4 0% beginning-of-line 3 0% looking-at 3 0% re-search-forward 2 0% line-end-position 2 0% match-data 1 0% # 1 0% - # 1 0% set-match-data 1 0% make-closure 11 1% looking-at 7 0% skip-syntax-backward 5 0% - c-beginning-of-current-token 2 0% skip-syntax-backward 2 0% looking-at 5 0% forward-comment 3 0% skip-syntax-forward 1 0% make-closure 1 0% buffer-modified-p 50 4% - c-backward-token-2 41 3% - c-backward-sws 11 1% - c-beginning-of-macro 3 0% beginning-of-line 2 0% re-search-forward 2 0% - back-to-indentation 2 0% line-end-position 2 0% looking-at 1 0% - # 1 0% set-match-data 7 0% looking-at 2 0% forward-comment 2 0% skip-syntax-backward 2 0% - c-beginning-of-current-token 2 0% skip-syntax-backward 1 0% buffer-modified-p 1 0% skip-syntax-forward 1 0% text-property-any 5 0% looking-at 1 0% scan-sexps 31 3% - c-at-macro-vsemi-p 13 1% looking-at 9 0% - c-backward-sws 7 0% looking-at 2 0% - c-beginning-of-current-token 1 0% looking-at 1 0% skip-syntax-backward 4 0% skip-syntax-backward 2 0% looking-at 53 5% - c-backward-token-2 49 4% scan-sexps 2 0% looking-at 1 0% - c-backward-sws 1 0% looking-at 12 1% - c-backward-sws 3 0% - c-beginning-of-macro 1 0% - back-to-indentation 1 0% skip-syntax-forward 1 0% looking-at 3 0% looking-at 1 0% forward-comment 1 0% skip-syntax-backward 1 0% skip-syntax-forward 1 0% c-laomib-get-cache 1 0% - c-back-over-compound-identifier 1 0% c-on-identifier 79 7% - c-looking-at-inexpr-block 38 3% scan-sexps 31 3% - c-backward-sws 12 1% - c-beginning-of-macro 2 0% - back-to-indentation 1 0% line-end-position 1 0% skip-syntax-forward 1 0% re-search-forward 1 0% make-closure 1 0% - # 1 0% set-match-data 1 0% looking-at 1 0% match-data 7 0% looking-at 3 0% skip-syntax-backward 2 0% - c-beginning-of-current-token 2 0% looking-at 2 0% forward-comment 10 0% looking-at 1 0% - c-backward-over-enum-header 1 0% scan-lists 1 0% - c-parse-state 1 0% - c-parse-state-1 1 0% - c-remove-stale-state-cache 1 0% - c-beginning-of-macro 1 0% re-search-forward 7 0% - c-determine-limit 4 0% parse-partial-sexp 3 0% - c-semi-pp-to-literal 3 0% parse-partial-sexp 6 0% - c-forward-decl-or-cast-1 3 0% - c-forward-type 2 0% - c-forward-name 2 0% - c-determine-+ve-limit 2 0% parse-partial-sexp 1 0% - c-forward-keyword-clause 1 0% - c-forward-sws 1 0% looking-at 1 0% scan-sexps 4 0% - c-font-lock-single-decl 4 0% - c-font-lock-declarators 4 0% - c-do-declarators 3 0% - c-forward-declarator 2 0% - c-forward-name 2 0% - c-determine-+ve-limit 2 0% parse-partial-sexp 1 0% - c-forward-decl-arglist 1 0% scan-lists 1 0% - c-syntactic-re-search-forward 1 0% re-search-forward 2 0% - c-back-over-member-initializers 1 0% - c-backward-sws 1 0% skip-syntax-backward 1 0% - c-parse-state 1 0% - c-parse-state-1 1 0% - c-remove-stale-state-cache 1 0% - c-beginning-of-macro 1 0% looking-at 2 0% - c-at-toplevel-p 1 0% - c-search-uplist-for-classkey 1 0% - c-looking-at-decl-block 1 0% scan-lists 1 0% - c-parse-state 1 0% - c-parse-state-1 1 0% c-append-to-state-cache 226 21% - c-font-lock-declarations 226 21% - c-find-decl-spots 221 21% - # 170 16% - c-get-fontification-context 166 16% - c-inside-bracelist-p 108 10% - c-looking-at-or-maybe-in-bracelist 69 6% - c-laomib-loop 41 3% - c-backward-sws 11 1% looking-at 8 0% forward-comment 6 0% - c-beginning-of-macro 1 0% beginning-of-line 1 0% - back-to-indentation 1 0% line-end-position 1 0% re-search-forward 3 0% - c-beginning-of-current-token 2 0% skip-syntax-backward 1 0% looking-at 2 0% skip-syntax-backward 2 0% skip-syntax-forward 1 0% text-property-any 21 2% - c-backward-token-2 16 1% - c-backward-sws 4 0% - c-beginning-of-macro 2 0% - back-to-indentation 1 0% line-end-position 1 0% skip-syntax-forward 1 0% re-search-forward 1 0% - # 1 0% set-match-data 3 0% skip-syntax-backward 2 0% looking-at 1 0% - c-beginning-of-current-token 1 0% looking-at 2 0% scan-sexps 6 0% - c-at-macro-vsemi-p 3 0% - c-backward-sws 2 0% looking-at 1 0% - c-beginning-of-current-token 1 0% looking-at 2 0% looking-at 1 0% looking-at 29 2% - c-backward-token-2 26 2% scan-sexps 2 0% looking-at 1 0% - c-backward-sws 1 0% looking-at 8 0% - c-backward-sws 3 0% skip-syntax-backward 2 0% looking-at 1 0% forward-comment 1 0% - c-beginning-of-macro 1 0% match-data 1 0% c-laomib-get-cache 55 5% - c-looking-at-inexpr-block 30 2% scan-sexps 16 1% - c-backward-sws 6 0% - c-beginning-of-macro 2 0% match-data 1 0% - back-to-indentation 1 0% line-end-position 1 0% beginning-of-line 5 0% looking-at 1 0% - c-beginning-of-current-token 1 0% skip-syntax-backward 1 0% skip-syntax-backward 1 0% # 7 0% looking-at 2 0% - c-backward-over-enum-header 2 0% scan-lists 3 0% - c-parse-state 2 0% - c-parse-state-1 2 0% - c-remove-stale-state-cache 2 0% - c-beginning-of-macro 2 0% - back-to-indentation 2 0% backward-prefix-chars 1 0% - c-beginning-of-macro 1 0% - back-to-indentation 1 0% backward-prefix-chars 43 4% - c-forward-decl-or-cast-1 35 3% - c-forward-type 21 2% - c-forward-name 18 1% - c-determine-+ve-limit 16 1% parse-partial-sexp 1 0% skip-syntax-backward 1 0% looking-at 5 0% looking-at 5 0% - c-forward-sws 3 0% looking-at 2 0% - c-check-qualified-type 2 0% - c-forward-over-compound-identifier 2 0% - c-forward-over-token 2 0% - c-forward-sws 2 0% looking-at 1 0% - c-add-type 1 0% - c-add-type-1 1 0% - c-syntactic-content 1 0% re-search-forward 5 0% - c-forward-name 5 0% - c-determine-+ve-limit 5 0% parse-partial-sexp 3 0% looking-at 6 0% - c-font-lock-single-decl 6 0% - c-font-lock-declarators 6 0% - c-do-declarators 6 0% - c-forward-declarator 3 0% - c-forward-name 1 0% - c-determine-+ve-limit 1 0% parse-partial-sexp 1 0% - c-forward-sws 1 0% looking-at 1 0% looking-at 2 0% c-syntactic-re-search-forward 1 0% looking-at 1 0% looking-at 1 0% - c-backward-sws 1 0% text-property-any 5 0% - c-bs-at-toplevel-p 5 0% - c-brace-stack-at 5 0% - c-update-brace-stack 5 0% - c-syntactic-re-search-forward 3 0% parse-partial-sexp 2 0% - c-beginning-of-macro 1 0% make-closure 1 0% - back-to-indentation 1 0% beginning-of-line 27 2% - c-font-lock-enclosing-decls 12 1% - c-syntactic-skip-backward 5 0% - c-beginning-of-macro 3 0% - back-to-indentation 2 0% line-end-position 1 0% backward-prefix-chars 1 0% looking-at 1 0% line-end-position 4 0% - c-literal-start 4 0% - c-semi-pp-to-literal 4 0% parse-partial-sexp 2 0% - c-backward-sws 2 0% skip-syntax-backward 7 0% - c-forward-sws 6 0% looking-at 5 0% - c-determine-limit 5 0% parse-partial-sexp 2 0% looking-at 1 0% - c-parse-state 1 0% - c-parse-state-1 1 0% - c-append-to-state-cache 1 0% scan-lists 3 0% - c-font-lock-enum-tail 2 0% - c-parse-state 2 0% - c-parse-state-1 2 0% - c-append-to-state-cache 1 0% - c-beginning-of-macro 1 0% - # 1 0% set-match-data 1 0% scan-lists 1 0% - c-backward-over-enum-header 1 0% scan-lists 2 0% - c-font-lock-complex-decl-prepare 2 0% c-backward-sws 1 0% - font-lock-fontify-syntactically-region 1 0% - font-lock-default-fontify-syntactically 1 0% - syntax-ppss 1 0% parse-partial-sexp 32 3% - c-before-context-fl-expand-region 32 3% - mapc 32 3% - # 32 3% - c-context-expand-fl-region 16 1% - c-fl-decl-end 13 1% - c-determine-limit 11 1% - c-semi-pp-to-literal 10 0% parse-partial-sexp 1 0% looking-at 1 0% parse-partial-sexp 1 0% - c-determine-limit-no-macro 1 0% - c-beginning-of-macro 1 0% beginning-of-line 2 0% - c-forward-declarator 1 0% - c-forward-name 1 0% - c-determine-+ve-limit 1 0% parse-partial-sexp 1 0% - c-syntactic-re-search-forward 1 0% - c-beginning-of-macro 1 0% beginning-of-line 1 0% - c-backward-sws 1 0% - c-beginning-of-current-token 1 0% looking-at 16 1% - c-fl-decl-start 5 0% - c-forward-type 4 0% - c-forward-name 2 0% - c-determine-+ve-limit 2 0% parse-partial-sexp 1 0% looking-at 1 0% - c-forward-sws 1 0% looking-at 1 0% looking-at 4 0% - c-determine-limit 4 0% parse-partial-sexp 2 0% - c-syntactic-skip-backward 1 0% - c-literal-start 1 0% - c-semi-pp-to-literal 1 0% parse-partial-sexp 1 0% - c-beginning-of-macro 1 0% - back-to-indentation 1 0% line-end-position 2 0% - c-looking-at-or-maybe-in-bracelist 2 0% - c-backward-token-2 2 0% scan-sexps 2 0% - c-literal-start 2 0% - c-semi-pp-to-literal 2 0% parse-partial-sexp 1 0% - c-parse-state 1 0% - c-parse-state-1 1 0% - c-remove-stale-state-cache-backwards 1 0% - c-state-literal-at 1 0% - c-state-pp-to-literal 1 0% parse-partial-sexp 387 37% Automatic GC 13 1% - command-execute 13 1% - call-interactively 10 0% - funcall-interactively 5 0% - self-insert-command 3 0% - c-after-change 3 0% - mapc 3 0% - # 3 0% - c-change-expand-fl-region 3 0% - c-fl-decl-end 1 0% c-backward-sws 1 0% - c-forward-declarator 1 0% - c-forward-name 1 0% - c-forward-sws 1 0% looking-at 2 0% - c-before-change 1 0% - c-determine-limit 1 0% parse-partial-sexp 1 0% - c-invalidate-sws-region-before 1 0% - c-literal-limits 1 0% c-full-pp-to-literal 5 0% - next-line 5 0% - line-move 5 0% - line-move-partial 5 0% - pos-visible-in-window-p 4 0% - jit-lock-function 4 0% - jit-lock-fontify-now 4 0% - jit-lock--run-functions 4 0% - run-hook-wrapped 4 0% - # 4 0% - font-lock-fontify-region 4 0% - c-font-lock-fontify-region 3 0% - font-lock-default-fontify-region 3 0% - font-lock-fontify-keywords-region 2 0% - c-font-lock-cut-off-declarators 2 0% - c-get-fontification-context 2 0% - c-inside-bracelist-p 1 0% - c-looking-at-or-maybe-in-bracelist 1 0% c-laomib-loop 1 0% - c-looking-at-inexpr-block 1 0% scan-sexps 1 0% - c-font-lock-declarations 1 0% - c-find-decl-spots 1 0% - # 1 0% - c-forward-decl-or-cast-1 1 0% looking-at 1 0% - c-before-context-fl-expand-region 1 0% - mapc 1 0% - # 1 0% - c-context-expand-fl-region 1 0% - c-fl-decl-end 1 0% - c-determine-limit 1 0% - c-semi-pp-to-literal 1 0% parse-partial-sexp 3 0% - byte-code 3 0% - read-extended-command 3 0% - read-extended-command-1 3 0% - completing-read 3 0% - completing-read-default 3 0% - read-from-minibuffer 1 0% redisplay_internal (C function) 7 0% - timer-event-handler 7 0% - apply 6 0% - c-force-redisplay 6 0% - c-font-lock-fontify-region 5 0% - font-lock-default-fontify-region 4 0% - font-lock-fontify-keywords-region 2 0% - c-font-lock-declarations 2 0% - c-find-decl-spots 2 0% - c-bs-at-toplevel-p 2 0% - c-brace-stack-at 2 0% - c-update-brace-stack 2 0% - c-syntactic-re-search-forward 2 0% parse-partial-sexp 1 0% - c-font-lock-enclosing-decls 1 0% - c-syntactic-skip-backward 1 0% - c-literal-start 1 0% - c-semi-pp-to-literal 1 0% parse-partial-sexp 1 0% re-search-forward 1 0% - font-lock-fontify-syntactically-region 1 0% - font-lock-default-fontify-syntactically 1 0% - syntax-ppss 1 0% parse-partial-sexp 1 0% - c-before-context-fl-expand-region 1 0% - mapc 1 0% - # 1 0% - c-context-expand-fl-region 1 0% - c-fl-decl-end 1 0% - c-determine-limit 1 0% - c-semi-pp-to-literal 1 0% parse-partial-sexp 1 0% - # 1 0% - completion--in-region-1 1 0% - completion--do-completion 1 0% - completion-try-completion 1 0% - completion--nth-completion 1 0% - seq-some 1 0% - seq-do 1 0% - mapc 1 0% - # 1 0% - # 1 0% - completion-basic-try-completion 1 0% - try-completion 1 0% - # 1 0% - complete-with-action 1 0% try-completion 0 0% ...