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.devel Subject: Re: Should `get-file-buffer' be implemented in Elisp? Date: Mon, 17 Jul 2023 16:11:33 +0300 Message-ID: <83y1je7ke2.fsf@gnu.org> References: <87pm4r1z03.fsf@localhost> <83fs5n8zaz.fsf@gnu.org> <87mszv1xur.fsf@localhost> <83cz0r8ygk.fsf@gnu.org> <87h6q31uf5.fsf@localhost> <87r0p6zy25.fsf@localhost> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40342"; mail-complaints-to="usenet@ciao.gmane.io" Cc: tomas@tuxteam.de, emacs-devel@gnu.org To: Ihor Radchenko Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Jul 17 15:12:08 2023 Return-path: Envelope-to: ged-emacs-devel@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 1qLO1I-000ANq-3U for ged-emacs-devel@m.gmane-mx.org; Mon, 17 Jul 2023 15:12:08 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qLO0a-0005rc-R5; Mon, 17 Jul 2023 09:11:24 -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 1qLO0S-0005pn-DV for emacs-devel@gnu.org; Mon, 17 Jul 2023 09:11:16 -0400 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 1qLO0R-00073P-Pm; Mon, 17 Jul 2023 09:11:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=STW+rpJsKYbHKwv+WlqlUX4pQijbEUwYNzRVlSmPqiU=; b=dEyDyQrOihZI ROGZb2xZI9INsZfwNnEgJnO5DzVdh7EoEJFCYbQCkHKbmSLjNyuZfldBGLmzfDZl7amjcWF+LnDlA bPFXwuzdk9IWmCWA9dsZP0159yjRy6HrAjWkkSU2F3B9Cz3msweVBoPg1JsPYjkclYKjCRYh42Dfg 73gVKIQx/+wH8DlY2bKfglvJRaxD2CkFJ+c24cJM4H6HI4nMKGU5FhWuHm4Gz6sZAX8e0uqsr82Kw ypmQCFvsdpAFSA0piiI8yO4fQd3UsXmKOpghvyZlqV9AOof1AJfnWEOrayD0T/H92r63ZDfSqZnvZ gS8N/adzLOU9ohsPEfHs+w==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qLO0I-0002GV-P1; Mon, 17 Jul 2023 09:11:14 -0400 In-Reply-To: <87r0p6zy25.fsf@localhost> (message from Ihor Radchenko on Mon, 17 Jul 2023 09:28:50 +0000) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:307929 Archived-At: > From: Ihor Radchenko > Cc: Eli Zaretskii , emacs-devel@gnu.org > Date: Mon, 17 Jul 2023 09:28:50 +0000 > > writes: > > > On Sun, Jul 16, 2023 at 08:19:10PM +0000, Ihor Radchenko wrote: > > > > [...] > > > >> scenarios. And in general lookup as well as hash tables start to > >> outperform alists just at 20-30 elements [1] > > > > For me, it's more like 45-ish: > > Right. The link I provided actually also mentions similar number. > > > How many people around here have regularly 1000 buffers? > > Well. Check out https://github.com/org-roam/org-roam > People routinely deal with thousands of buffers there and complain about > that. > > I also did a benchmark for opening several thousands of files in Emacs > and the performance was quite disappointing. (Though, admittedly, not > because of `get-file-buffer'). > > > And even at 100, the absolute time is rather negligible. Somewhere > > near 5000 buffers my (not very fast) machine reaches the 100ms > > area for alists and lingers in the 2ms area for hashes (that would > > be where I'd start worrying). > > 100ms is fast when you do it once. But `get-file-buffer' may be called > rather frequently by `with-temp-buffer'. Performance improvement when there are many buffers is indeed a worthy goal, but if we want to make get-file-buffer as fast as possible, leaving it in C makes more sense. We can call hash-table functions from C as well; moreover, we can call them in a more efficient way, bypassing validity checks that primitives often perform on their arguments.