From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Pip Cet Newsgroups: gmane.emacs.devel Subject: Re: MPS: weak hash tables Date: Tue, 02 Jul 2024 15:03:44 +0000 Message-ID: References: <86ed8cc4un.fsf@gnu.org> <86zfqzc3ky.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="1524"; mail-complaints-to="usenet@ciao.gmane.io" Cc: =?utf-8?Q?Gerd_M=C3=B6llmann?= , eller.helmut@gmail.com, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jul 02 17:30:19 2024 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 1sOfSV-00009x-Aj for ged-emacs-devel@m.gmane-mx.org; Tue, 02 Jul 2024 17:30:19 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOfRi-0005Y8-7x; Tue, 02 Jul 2024 11:29:30 -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 1sOf2t-0000fo-Ku for emacs-devel@gnu.org; Tue, 02 Jul 2024 11:03:51 -0400 Original-Received: from mail-4316.protonmail.ch ([185.70.43.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sOf2r-0004db-ES for emacs-devel@gnu.org; Tue, 02 Jul 2024 11:03:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1719932626; x=1720191826; bh=cgohDJ4xxKNle9EEqqhtyvr+zt8J9FxjaCljmigwVSE=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=rddm3szjCjf/MeWIAOcgKr70AyfFXctXlLp7p5CrkWDmPhjZXGtnrUOvhID5SALbJ pIDxrDoF7FAuu7/xYjkkxDYQyldL1hJ+/+ua+sbZ0GaeKZKCwslb3NLRoXKk6DGvFO 5wQ/37HLkh3N0HcPXWI1vGqbw07YGctnnyzNoY+TG9iLOgYxMFH+v9kHANlClWBZqU fw36byMBCqrDStuF5aOwfrft5Cn98/skEhOvhIlIW0YNcqvBYs6zhjL5WVR4EEP30t x5xz+9IZZKJcpZKMzdCHOwK1taOEqfpx2ifwgw0PSzbGo8EMkUu65HgFnScgdXWMC8 axH8ZpFKjfnCg== In-Reply-To: <86zfqzc3ky.fsf@gnu.org> Feedback-ID: 112775352:user:proton X-Pm-Message-ID: 82823793d3bd35dfc08e83a92d2ef782fe0be00a Received-SPF: pass client-ip=185.70.43.16; envelope-from=pipcet@protonmail.com; helo=mail-4316.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 02 Jul 2024 11:29:29 -0400 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:321175 Archived-At: On Tuesday, July 2nd, 2024 at 13:42, Eli Zaretskii wrote: > > From: Gerd M=C3=B6llmann gerd.moellmann@gmail.com >=20 > > Cc: pipcet@protonmail.com, eller.helmut@gmail.com, emacs-devel@gnu.org > > Date: Tue, 02 Jul 2024 15:16:54 +0200 > >=20 > > Eli Zaretskii eliz@gnu.org writes: > >=20 > > > Do we even use weak objects in Emacs on this branch? If we do, what > > > do we use them for? > >=20 > > Yes, Pip's weak hash tables, and vectors for BUF_MARKERS. >=20 > So I guess they will work better in the 32-bit builds than in the > 64-bit ones? Because AFAIU what that text says is that they > implemented this feature only in the IA-32 builds, and in the other > cases the behavior is sub-optimal. The code needs fixing for IA-32, and will conceivably be a little faster on= those machines than it is on 64-bit machines. This will probably be notice= able only for very large hash tables, but may be noticeable for normal numb= ers of markers in a buffer. Having looked at the MPS code, and sorry for being verbose: * all this is relevant to large objects, which MPS's design doesn't really = favor. For strong references, you scan an entire object or none of it. This= is a potential problem since Emacs can have very large objects. * For weak references, it's even worse, because when you scan an entire obj= ect to satisfy a client request to it (which triggered a protection signal)= , MPS uses a "strong" scan and doesn't splat any references. * so, only for weak references, and only when certain CPU instructions are = used, and only on 32-bit x86 machines (there's some code for x86-64 and aar= ch64, as well as macOS, but not enough to actually do anything) on Windows = and Linux, there's a special optimization which avoids scanning the entire = object: a machine instruction is simulated. * Since the point is to avoid calling the scan function for the entire obje= ct, MPS needs a different algorithm to decide whether the word is a weak (e= xact) reference, or plain old data that doesn't refer to anything. * They decided to treat all multiple-of-four values (except for 0) as refer= ences, and all with a remainder when divided by four as non-references. Tha= t clashes with our usual Lisp_Object convention, but miraculously works out= for fixnums, whose integer value is congruent to 2 modulo 4. No, I don't k= now why they didn't use a special sub-scan function which takes a range int= o the object (possibly they don't remember object starts at all?) That means we must do one of the following: 1. mangle all Lisp_Objects to pointers or fixnums when storing them in a we= ak hash table, and unmangle them upon retrieval 2. not use 32-bit x86 machines 3. modify MPS 4. throw caution to the wind and just hope it works I started implementing (1) (which is why the hashes are now fixnums rather = than uint32_t), then realized I was doing (2). I looked at MPS and the modi= fications to disable this code, while trivial, cannot be performed without = rebuilding the library. And, yes, I'm afraid on 32-bit x86 we're currently = using option (4), which is very annoying. I'm not at all sure what the right thing to do is in our present situation.= I'm not opposed to mangling Lisp_Objects, provided we can revise struct ig= c_header to contain the three Emacs tag bits directly. However, performance= of large weak hash tables will be poor on all machines. Any advice would be appreciated. Pip