From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#70036: a fix that Date: Fri, 19 Apr 2024 08:09:50 +0200 Message-ID: <87wmot289d.fsf@thornhill.no> References: <4e670617-6483-4159-a5cf-27a921764c38@email.android.com> Reply-To: Theodor Thornhill 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="15423"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , 70036@debbugs.gnu.org, felician.nemeth@gmail.com To: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Apr 19 08:11:03 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 1rxhSg-0003ha-K7 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 19 Apr 2024 08:11:03 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rxhSW-0007wA-O2; Fri, 19 Apr 2024 02:10:52 -0400 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 1rxhSS-0007vZ-FD for bug-gnu-emacs@gnu.org; Fri, 19 Apr 2024 02:10:49 -0400 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 1rxhSS-0003du-75 for bug-gnu-emacs@gnu.org; Fri, 19 Apr 2024 02:10:48 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rxhSf-0004FI-O9 for bug-gnu-emacs@gnu.org; Fri, 19 Apr 2024 02:11:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 19 Apr 2024 06:11:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70036 X-GNU-PR-Package: emacs Original-Received: via spool by 70036-submit@debbugs.gnu.org id=B70036.171350701916269 (code B ref 70036); Fri, 19 Apr 2024 06:11:01 +0000 Original-Received: (at 70036) by debbugs.gnu.org; 19 Apr 2024 06:10:19 +0000 Original-Received: from localhost ([127.0.0.1]:56957 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rxhRy-0004EJ-SB for submit@debbugs.gnu.org; Fri, 19 Apr 2024 02:10:19 -0400 Original-Received: from out-176.mta1.migadu.com ([95.215.58.176]:12883) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rxhRv-0004Cq-FR for 70036@debbugs.gnu.org; Fri, 19 Apr 2024 02:10:17 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1713506993; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Qu846u6yOAf5RpzJz31PY4EDHfWmcpYSaUcDI3BmdGo=; b=GgfsoztOKNneNKlqFY4xIq7Ob/pbSlC/6Xq5ENCQ2yXDz/S0xZ3Yvi8NsujpGElUJ4GFXV 1luafhRZtnngHQX5VX+9c8wAicWRmqLxEGGpxzWxCGAY+PT7PVeX5xEQBZPUJ6SCLspDLG lASyEI+altC6F30HBynwgY5AUSC9tQG3u+dEjm0JiFVLzdoyohMMRXzVMvp0VK7CHL6V9C lI21q2uYHWDt/BD2xQUsPZyUwiQbCYDBk00tvXxV8SbLaKqhCUdEX8r2lcmoIfC6zIY5PT 0XYHv8XyIMVlUTKRl/+J+yKJzmzaNOB8eQbkgs0WgY/8aa6Pg98csBcd4h0odg== In-Reply-To: X-Migadu-Flow: FLOW_OUT 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:283632 Archived-At: Jo=C3=A3o T=C3=A1vora writes: > On Thu, Apr 18, 2024 at 11:06=E2=80=AFPM Jo=C3=A3o T=C3=A1vora wrote: > >> Anyway is this the hotspot I should be trying to optimize? >> >> > 9 4% - find-buffer-visiting > > Alright, i've reproduced this > > 33 5% - eglot-handle-notification > 33 5% - apply > 33 5% - # > 29 4% - find-buffer-visiting > 29 4% - file-truename > 29 4% - file-truename > 25 4% - file-truename > 25 4% - file-truename > 25 4% - file-truename > 25 4% - file-truename > 25 4% + file-truename > > But I have to say, I wouldn't call this a severe performance penalty. > I followed your instructions very closely and invoked Emacs like this: > > emacs -Q foo/bar/baz/foo/bar/baz/foo/bar/baz/foo/bar/baz/gin/fs.go -f > go-ts-mode > > The directory is ~/tmp/theo/foo/bar... so it's a pretty long path with > many directories all in all. Great! > > But I didn't have to wait 10 seconds for the LSP to settle down! It was > pretty snappy on my 2018 Lenovo T480 running Archlinux. And if I > profile anything other than the initial M-x eglot (which normally happens > only once in a work session), I don't find any file-truename in the profi= le. > This is true to some extent, but varies a lot from server to server, as you've also noted earlier. I have an even stronger computer, a 2023 P1 gen 5, I believe, running ubuntu. Some servers send _all_ diagnostics on every keystroke. > So my perception is that it must have spent around 4% of 1 second in > file-truename. > > Anyway the reason this shows in this profile is because this project > with this particular server sends a lot of publishDiagnostics upfront. > That's OK. Gopls is a very good server. I think I see a fix. But can > you qualitatively describe the Eglot experience. Do you notice any > input lag or something like that? With this project? I didn't feel _any_ > lag. > Super snappy. Maybe the JSON serde kicking in? > In this particular project I don't notice any input lag. But on every java project at work I absolutely do. With my fix I don't. So if we solve this in any particular way that will be a huge benefit for everyone using java and other either suboptimal lsp servers or languages in general. > Anyway, the idea I suggested earlier is in the patch after my sig. > > Let's think: LSP's publishDiagnostics coming from the server deals > in URIs, right? And we inform the LSP server about URIs, too, right? > So the URI is always LSP's idea of the resource identifier (and it likes > to have truename URI). Sure, like in my key/value store. (apart from symlinking) > > My last "better fix" commit records this URI in the buffer as a buffer > local variable eglot--cached-tdi and it has to do that for every didOpen. > > So, to find an open buffer pertaining to a certain LSP's publishDiagnost= ics > it suffices in theory to go through all the buffers that have a non-nil > cached > URI and compare that. > > No need to convert from URI to file names, not for this job at least! > I tried this and it worked fine. > > When I do that, the profile is completely free of those 4% that > bothered you. > > I'm still testing this for edge cases and will sleep on it, but it seems > promisingly simple at least. I can't run unit tests right now, because > a recent adventurous commit by Stefan Monnier broke them all :-) > but I'm confident that will be fixed soon... > > I hope you can try this patch. I will :) > > Jo=C3=A3o > > diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el > index 90a607075d3..38a16b15e4c 100644 > --- a/lisp/progmodes/eglot.el > +++ b/lisp/progmodes/eglot.el > @@ -2381,6 +2381,9 @@ eglot-handle-notification > (lambda () > (remhash token (eglot--progress-reporters > server)))))))))) > > +(defvar-local eglot--cached-tdi nil > + "A cached LSP TextDocumentIdentifier URI string.") > + > (cl-defmethod eglot-handle-notification > (_server (_method (eql textDocument/publishDiagnostics)) &key uri > diagnostics > &allow-other-keys) ; FIXME: doesn't respect `eglot-strict-mod= e' > @@ -2391,9 +2394,14 @@ eglot-handle-notification > ((=3D sev 2) 'eglot-warning) > (t 'eglot-note))) > (mess (source code message) > - (concat source (and code (format " [%s]" code)) ": " > message))) > + (concat source (and code (format " [%s]" code)) ": " > message)) > + (find-it (uri) > + (cl-loop for b in (buffer-list) Could we rather use eglot--managed-buffers, like in my patch? there shouldn't be a need to loop through say 200 buffers that are unrelated to the project in question, right? Apart from this I agree, and will try it. Thanks, Theo