From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Bj=C3=B6rn?= Lindqvist Newsgroups: gmane.emacs.bugs Subject: bug#74357: c-mode: Some syntactic constructs cause unreasonable typing lag Date: Fri, 15 Nov 2024 15:08:09 +0100 Message-ID: References: <86v7wphrmi.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28130"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Alan Mackenzie , 74357@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Nov 15 15:10:34 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 1tBx1t-00079E-PW for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 15 Nov 2024 15:10:33 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBx1U-0004VN-0E; Fri, 15 Nov 2024 09:10:10 -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 1tBx1O-0004V4-IX for bug-gnu-emacs@gnu.org; Fri, 15 Nov 2024 09:10:03 -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 1tBx1O-0006jA-9U for bug-gnu-emacs@gnu.org; Fri, 15 Nov 2024 09:10:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=Date:From:In-Reply-To:References:MIME-Version:To:Subject; bh=7zMJOzbXrCSVInZP0ce1G6erbIpmyX9P4G16owzpeU0=; b=PCOaby0EGf5HBxgRS4BWI5Wu+MNQOx523LpmjcLeEFXxmssFHY7CsEjVuJDH/wjgFjcpyc6QC13PycouPW5EQ1iyf8mL9s+IoOfp+pujy18fcoeKG1Lowsk115v7bt3pkxE/F7XG3H4G1Jw5DTXizCtnBrDMM7IEa/5K3vH9o88dPJJ2xc6jqgdtoquqEcafJZuVKsMUoSMip81A5hDKgtRWv/2K1BF9NGJWVcUoF2B0AQetdukH0SP+7Qe5sdDfupLNUJByCAUdkNWxt/+B2nlTFwPOYTyVETMtFHcgTzO/b0LiFI5CqWqsjkeuaosB1X/FEuzWLdXO2EAAcshiDQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tBx1N-0006Yy-Tx for bug-gnu-emacs@gnu.org; Fri, 15 Nov 2024 09:10:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Bj=C3=B6rn?= Lindqvist Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 15 Nov 2024 14:10: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.173167977025173 (code B ref 74357); Fri, 15 Nov 2024 14:10:01 +0000 Original-Received: (at 74357) by debbugs.gnu.org; 15 Nov 2024 14:09:30 +0000 Original-Received: from localhost ([127.0.0.1]:49054 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tBx0r-0006Xx-Fm for submit@debbugs.gnu.org; Fri, 15 Nov 2024 09:09:29 -0500 Original-Received: from mail-oo1-f47.google.com ([209.85.161.47]:59868) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tBx0o-0006Xi-Gu for 74357@debbugs.gnu.org; Fri, 15 Nov 2024 09:09:27 -0500 Original-Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-5ebc0c05e25so898324eaf.3 for <74357@debbugs.gnu.org>; Fri, 15 Nov 2024 06:09:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731679701; x=1732284501; darn=debbugs.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=7zMJOzbXrCSVInZP0ce1G6erbIpmyX9P4G16owzpeU0=; b=cZwP0551gR7ztVpwI6VSvwkzUdkGQkmNXAW2FhzOOVBblNOQIn6/2jwFklQot4S2OS Wbs2DhUKV6KxOt7kp+B6FelN18GKcz70s98rqZFghqdrVYT7Otq4kpT72Bq184YUKWcJ LIUJmER9UTH9sCxO9MOGUYJX7V7A3jIB10fRxRagtL9xmwwuJ6HnVMJfdODOSX3CxWSH ZTxPe+2TQlqZEeeyEnlZ1stybjNTEW5h8Cy50pCMa7jPS6X+J8A6M8vsiDkQTUEFeYLo c6phsaWKbfx3qcnI++F8QV5p3ofD9XfJuHSICLfo/7kkO3Xm2O7XRSwSYC/nNa1GQrRN jpSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731679701; x=1732284501; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7zMJOzbXrCSVInZP0ce1G6erbIpmyX9P4G16owzpeU0=; b=wFf2st6jFtqipAi3baBPu80u71a9PBC3Jd1i6O0LwG0UVWGEQEwiiLdGg1BWrnLP1i cKTWlqE1XEwoQpzK3jAtplfx2HDWgvUT+djUlENIYh39l2DXrHWMJkc4wFh2s7wszEBK Y3Y/AGOZXF6OMcgoUtIF7R9aUuC99vTCnu7SqsCydsC3Vn7GMBLLF9LCjS6f5XEYZhGf YRMDF1emSqj74sJ+3m/GS8Pd+WYpPtDqXZhU6ee0LL33y7HnP4UgQGw0nZ2NZEMea1sS CpTRg1875vK3Ay+7PmhXrkSMqlQ7IXL7+avh38EVr4xvUJ257h4ZDe8gF/jvN1s4EgiD H8dw== X-Forwarded-Encrypted: i=1; AJvYcCWJTBQ5+G3KVCufOLakn/2FOLiDRAE5yszypExUEfHtPlOC6CzqNof1A8Yf1aEcwKmQFK5wWw==@debbugs.gnu.org X-Gm-Message-State: AOJu0Yz/zEH08bV0m76/OK3kc3zvJeY0b9HPSvVTtEywv2tmNUlKwMmD 1paL4DIhPDwCmHoV82pZ5I0D02leB3sEze6tFeeSoPx7T0ZQ4SyQKnlIm+2iaXBxEXk+KpzMfV2 qfa9f+U277KrEtVPViJxznF9jbkg= X-Google-Smtp-Source: AGHT+IHgN7OPFVDpjq531y3apQpK01OossjdwtWrdPHq70arLieEb5zWwotvGcrJpSiKV2NWSsUOloShoJZN6ZPwEW4= X-Received: by 2002:a05:6359:14c9:b0:1aa:c73d:5a8a with SMTP id e5c5f4694b2df-1c6cd285418mr141127255d.16.1731679700790; Fri, 15 Nov 2024 06:08:20 -0800 (PST) In-Reply-To: <86v7wphrmi.fsf@gnu.org> 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:295393 Archived-At: > > From: Bj=C3=B6rn Lindqvist > > Date: Thu, 14 Nov 2024 21:39:53 +0100 > > > > This bug has been present in c-mode for at least a year, but I haven't > > gotten around to report it. The reason is that bugs about latency are > > erratic and tricky to triage. Typing when the cursor is on some > > syntatic constructs in c-mode causes severe lag on the order of several > > hundred milliseconds on my (admittedly slow) laptop. The lag > > makes c-mode almost unusable. Here is an MWE: > > > > void foo(uint dc_dim, uint sc_dim, > > uint fy_dim, uint fx_dim, > > __global const float * restrict F, > > uint sy_dim, uint sx_dim, > > __global const float * restrict S, > > uint padding, > > __global float * restrict D) { > > uint dy_dim =3D sy_dim + 2 * padding - fy_dim + 1; > > uint dx_dim =3D sx_dim + 2 * padding - fx_dim + 1; > > > > // Place cursor at "y" in "dy_dim". Hold "y" and observe lag. > > uint dn =3D dc_dim * dy_dim * dx_dim; > > uint sn =3D sc_dim * sy_dim * sx_dim; > > } > > > > I can make typing even laggier by wrapping foo in foo, like this: > > > > void foo(...) { > > ... > > void foo(uint dc_dim, uint sc_dim, > > uint fy_dim, uint fx_dim, > > __global float * restrict F, > > uint sy_dim, uint sx_dim, > > __global float * restrict S, > > uint padding, > > __global float * restrict D) { > > uint dy_dim =3D sy_dim + 2 * padding - fy_dim + 1; > > uint dx_dim =3D sx_dim + 2 * padding - fx_dim + 1; > > > > // Place cursor at d[y]_dim. Hold "y". Observe lag in c-mode. > > uint dn =3D dc_dim * dy_dim * dx_dim; > > uint sn =3D sc_dim * sy_dim * sx_dim; > > } > > } > > > > The more times I wrap foo the slower c-mode gets. So if you have a > > fast computer try nesting foo in foo 50 times... I have observed the > > same annoying input lag on multiple computers and I don't use any > > special c-mode configuration. > > 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. I want to emphasize that lag is present in normal code too, but easier to detect in these specially crafted samples. My system-configuration-features: "ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG JSON LCMS2 LIBOTF LIBSYSTEMD LIBXML2 M17N_FLT MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB" Profiler report: https://gist.github.com/bjourne/842695100e99c8fd6ef87fcdd0a6ed0b --=20 mvh/best regards Bj=C3=B6rn Lindqvist