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?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Newsgroups: gmane.emacs.bugs Subject: bug#70036: a fix that Date: Thu, 18 Apr 2024 16:32:33 +0100 Message-ID: References: <87le63xzjt.fsf@thornhill.no> 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="10404"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , 70036@debbugs.gnu.org To: Theodor Thornhill , Felician Nemeth Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Apr 18 17:34:16 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 1rxTmC-0002UY-Jd for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 18 Apr 2024 17:34:16 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rxTlm-0001T8-Pd; Thu, 18 Apr 2024 11:33:50 -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 1rxTlk-0001Sh-VC for bug-gnu-emacs@gnu.org; Thu, 18 Apr 2024 11:33: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 1rxTlk-0007UW-JF for bug-gnu-emacs@gnu.org; Thu, 18 Apr 2024 11:33:48 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rxTlx-00006E-Vg for bug-gnu-emacs@gnu.org; Thu, 18 Apr 2024 11:34:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <87le63xzjt.fsf@thornhill.no> Resent-From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 18 Apr 2024 15:34: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.171345438932491 (code B ref 70036); Thu, 18 Apr 2024 15:34:01 +0000 Original-Received: (at 70036) by debbugs.gnu.org; 18 Apr 2024 15:33:09 +0000 Original-Received: from localhost ([127.0.0.1]:53057 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rxTl6-0008Ro-CV for submit@debbugs.gnu.org; Thu, 18 Apr 2024 11:33:08 -0400 Original-Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]:60736) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rxTl4-0008Qf-8B for 70036@debbugs.gnu.org; Thu, 18 Apr 2024 11:33:07 -0400 Original-Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2d094bc2244so15779341fa.1 for <70036@debbugs.gnu.org>; Thu, 18 Apr 2024 08:32:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713454366; x=1714059166; darn=debbugs.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=4/QDhALe5ZENiON9OTNnMEj1KPhuZKBcwVJcY+xHJFU=; b=cjux4CgaBeTYKBiIM6NGfzZyBRkX4admUJEuleuh7vpxtmPh8GsxuVax3hX6ljMtXu Om8U2hkVvgZ9L4ACYWLDj5G8Y2FfKzh+IuflIOPDuTjmhlKB2i8kUmPUF3QaajwvSdiQ 4N8JOgqAZKsm0SOGzYzzOjRaTelsPdjSaKn8Al36+PvUY48v7CEGtS7S0obN2iS+we2i tOxR1Yr/N98sAywmUc7acGmhkazYb2mbmauTX8oxgKBOFjy4hEIk6bgVSom7tChnGA82 /w+3rO8uszFoGxLdKFnymB3xkAoDuNC8Ue3xO+NgpRRN652LuQy3/mFjYTXEZF6Yd26H aCdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713454366; x=1714059166; h=content-transfer-encoding:cc:to:subject:message-id:date:from :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4/QDhALe5ZENiON9OTNnMEj1KPhuZKBcwVJcY+xHJFU=; b=apYwSE5gKHOypTalDHA84K1DKWCGF314wBIeZSfBVwD80kP5JoptoY+vBhRCDNCdPN V8CADWwyXC5mPWbfgKjrDHgHEdcTzegeQaV0af9xleIFO1whwluTqFw1Xol0Y3sRebqb i0VomBahtRU8AgaT0ojYUyyUXGmr7YpsS86QcNXfogl+yZxzkTDgdkNtPmtPzfPGNQcF 0Wg8aABPrGwXAWItaCmxI+KewhstQM+XX1wJr/Ah7kwOlZS2z5uwdWVD1Pl5XlCfftMI 0VJBb7VJh89GrfA0HRpfFpPrLdn7hRMYumIj9XgQoFYKQDTr5AjtoJtudpd57c6J2XyU oemQ== X-Forwarded-Encrypted: i=1; AJvYcCWuY4le2iKEGVxQiSVorSj52Hw53BK6nuBTn714O6S7AV7LuyUU6jh3h2yRSgmwaHzN+liu2dKuXVw2bieJm0R2khdUwts= X-Gm-Message-State: AOJu0YzMBSF1HNpQzUSQsoPdQkg8a4Gi5VNXzW4/Ja7lZM7s63ccg+Ar TgG6BB4pYsm/Z/LKWVhLupFb45FDHXbeWWJ3aJsZOlHu9hfYAC20UhWxheGvY0/AmcDM2KPhn6u MqBSz60KYQ+WJUtE7/riK9tjEsos= X-Google-Smtp-Source: AGHT+IFb47EnrRjs7DwM8ssqQud1eUFhmsXogT0wGxRU1m9nh/HPw6+zUYuhfm6Wll61zgO1axOh3cN5avzEtEsUe1U= X-Received: by 2002:a05:651c:622:b0:2d8:729f:cf3a with SMTP id k34-20020a05651c062200b002d8729fcf3amr1579998lje.32.1713454365697; Thu, 18 Apr 2024 08:32:45 -0700 (PDT) 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:283573 Archived-At: So I've read up on the bug report and I had a close look at the Eglot usage profiles (not the micro-benchmarks, those are reasonably irrelevant in what concerns Eglot). I see these kinds of things in Theodor's profiles 18 8% - eglot--TextDocumentPositionParams 18 8% - eglot--TextDocumentIdentifier 18 8% - eglot--path-to-uri 15 7% - file-truename 14 6% - file-truename 14 6% - file-truename 11 5% - file-truename 11 5% - file-truename 11 5% - file-truename 10 4% - file-truename 10 4% - file-truename 8 3% - file-truename 8 3% - file-truename 8 3% - file-truename 5 2% - file-truename 3 1% - file-truename 2 0% - file-truename 1 0% file-truename I could reproduce this, but never even close to the amount of ~7-8%. Best I could get was 1% and I had to work pretty hard for it. If I invoke completion or something heavier like that, it completely dominates the profile. 25 1% - eglot--TextDocumentPositionParams 23 1% - eglot--TextDocumentIdentifier 23 1% - eglot-path-to-uri 13 0% - file-truename 13 0% - file-truename 13 0% - file-truename 13 0% file-truename Maybe that's because file-truename is a recursive function that becomes slower as the path it's asked to analyse becomes longer (obviously, there can be a symlink at every junction). So let's assume for the sake of argument that it's frequent for users to have very long file names with very many components or that the 1% overhead on the average path length is a real performance problem for people. If so, I think this simpler patch after my sig is all we need, as it completely clears the profile of any "file-truename". I have reverted the earlier patch and pushed a patch very similar to the one after my sig. I'm interested in more details of exactly what constitutes actual usage, i.e. what did you do while recording a cpu or mem profile. As to the symlink-outside-the-project issue that Felici=C3=A1n raised, I was not aware of that bug. It seems a separate bug at any rate. I've also noticed that the Eglot automated tests are failing. That too is unexpected. I will have a look at that, too. Jo=C3=A3o commit 23d6517b2499089f775640b88958774ac2c91049 Author: Jo=C3=A3o T=C3=A1vora Date: Thu Apr 18 08:03:10 2024 -0500 Better way to fix bug#70036 Cache eglot--cached-tdi per buffer, like we do with some many other variables already, to avoid frequent expensive recomputation of a value that requires potentially many 'file-truename' calls. diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 806265544d6..6196aaff7a3 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -2517,12 +2517,17 @@ eglot-handle-request (t (setq success :json-false))) `(:success ,success))) +(defvar-local eglot--cached-tdi nil + "A cached LSP TextDocumentIdentifier URI string.") + (defun eglot--TextDocumentIdentifier () "Compute TextDocumentIdentifier object for current buffer." - `(:uri ,(eglot-path-to-uri (or buffer-file-name - (ignore-errors - (buffer-file-name - (buffer-base-buffer))))))) + `(:uri ,(or eglot--cached-tdi + (setq eglot--cached-tdi + (eglot-path-to-uri (or buffer-file-name + (ignore-errors + (buffer-file-name + (buffer-base-buffer))))))))) (defvar-local eglot--versioned-identifier 0) --=20 Jo=C3=A3o T=C3=A1vora