From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#41200: Displaying a tooltip with x-show-tip gets very slow as more faces are defined Date: Fri, 15 May 2020 14:05:24 +0300 Message-ID: <837dxd31cb.fsf@gnu.org> References: <8fd8896a-cd5c-66f4-4792-f65cac4dc4f5@gmail.com> <83lflx896q.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="ciao.gmane.io:159.69.161.202"; logging-data="87013"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 41200@debbugs.gnu.org To: =?UTF-8?Q?Cl=C3=A9ment?= Pit-Claudel Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri May 15 13:06:19 2020 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 1jZYAU-000MYD-Tf for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 15 May 2020 13:06:18 +0200 Original-Received: from localhost ([::1]:34420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZYAT-0005gC-Vw for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 15 May 2020 07:06:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54092) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZYAE-0005eX-A8 for bug-gnu-emacs@gnu.org; Fri, 15 May 2020 07:06:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52673) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jZYAE-0006tr-0M for bug-gnu-emacs@gnu.org; Fri, 15 May 2020 07:06:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jZYAD-0006xP-OY for bug-gnu-emacs@gnu.org; Fri, 15 May 2020 07:06:01 -0400 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 May 2020 11:06:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41200 X-GNU-PR-Package: emacs Original-Received: via spool by 41200-submit@debbugs.gnu.org id=B41200.158954074526706 (code B ref 41200); Fri, 15 May 2020 11:06:01 +0000 Original-Received: (at 41200) by debbugs.gnu.org; 15 May 2020 11:05:45 +0000 Original-Received: from localhost ([127.0.0.1]:35986 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jZY9w-0006wg-Pz for submit@debbugs.gnu.org; Fri, 15 May 2020 07:05:45 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:46580) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jZY9v-0006wN-CX for 41200@debbugs.gnu.org; Fri, 15 May 2020 07:05:43 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:34554) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZY9q-0006rd-5u; Fri, 15 May 2020 07:05:38 -0400 Original-Received: from [176.228.60.248] (port=4703 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1jZY9p-0003HL-7H; Fri, 15 May 2020 07:05:38 -0400 In-Reply-To: (message from =?UTF-8?Q?Cl=C3=A9ment?= Pit-Claudel on Tue, 12 May 2020 22:41:24 -0400) 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" Xref: news.gmane.io gmane.emacs.bugs:180310 Archived-At: > Cc: 41200@debbugs.gnu.org > From: Clément Pit-Claudel > Date: Tue, 12 May 2020 22:41:24 -0400 > > > So I think if we want to support such large amounts of faces, we > > should not store them in alists, but in a more efficient data > > structure. > > Indeed, you're completely right; thanks! Replacing face_alist and Vface_new_frame_defaults with hash tables makes the worst example about 10 times faster, and with that change tooltips now take 30 to 50ms to display instead of 500-600ms in my real-life use case (my usual config). I have attached a patch. > > I left a few questions in the code; I hope that's OK. I have a few more questions that are not part of the code: > > * I removed the function frame-face-alist and changed the type of the variable face-new-frame-defaults. Both were documented as internal. Should I add an ELisp implementation of frame-face-alist for compatibility? (It wouldn't be a perfect shim, since modifying its return value wouldn't do the same). For face-new-frame-defaults it's a bit trickier, since the variable now holds a hash table. Should I change its name to make the change obvious, at least? I'd like to keep the old face-new-frame-defaults and frame-face-alist for compatibility, but mention in the doc strings that they no longer return modifiable values, and perhaps deprecate them. > * The name face_hash isn't ideal, since there's already a distinct notion of face hashes (hash codes). Can you think of a better name? face_hash_table? > * I imagine that this change needs to be advertised somewhere, but I'm not sure where; NEWS? Let's think about this after we figured out what changes are needed in the current functions and variables. > Lastly, do the following new profiles suggest other opportunities for improvement? I don't think so, but if the behavior is now linear or sub-linear, it's the best we can expect, since creating a new frame must walk over all the faces. > + // QUESTION: is this where this should be initialized? Yes, I think so. But do we need to do anything when frame is deleted as well? > + fset_face_hash > + (f, make_hash_table(hashtest_eq, DEFAULT_HASH_SIZE, DEFAULT_REHASH_SIZE, ^^ Our C coding conventions are to leave one space between the function's name and the opening parenthesis (here and elsewhere in the patch). > -DEFUN ("frame-face-alist", Fframe_face_alist, Sframe_face_alist, > +// QUESTION: Should I add an ELisp version of frame-face-hash? You mean, frame-face-alist, right? Yes, most definitely: I imagine a lot of code out there uses that, and we wouldn't want to break that. And I'm not sure we should have it only in Lisp: perhaps we should maintain the alist as well, and add/remove to/from it when a face is added or removed in the hash table. Otherwise this change of internals will have painful effect on packages that use the current APIs. > + Lisp_Object lface = HASH_KEY(table, idx); > + Lisp_Object face_id = Fget (lface, Qface); > + // FIXME why is (get 'tab-line 'face) 0? A bug, I guess. > + if (!FIXNATP (face_id)) > + // FIXME: I'm not sure what to do in this case I'm not sure I understand why do you need to look at the existing face's 'face' property? The original code didn't. > DEFVAR_LISP ("face-new-frame-defaults", Vface_new_frame_defaults, > doc: /* List of global face definitions (for internal use only.) */); > - Vface_new_frame_defaults = Qnil; > + Vface_new_frame_defaults = > + make_hash_table (hashtest_eq, DEFAULT_HASH_SIZE, DEFAULT_REHASH_SIZE, > + DEFAULT_REHASH_THRESHOLD, Qnil, Qnil); Why do we need to start with a non-default hash-table?