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?Gerd_M=C3=B6llmann?= Newsgroups: gmane.emacs.devel Subject: Re: MPS: weak hash tables Date: Tue, 02 Jul 2024 11:37:23 +0200 Message-ID: References: <2syUQ04IbTWqDJjMfKSrtzWMWmFGq1GIOwSxv_r6BEyNDtk7ADADKjZk-90g9tSS9SKWppkiq6_zihUtsoE1spiopaOI6-v9inQrGxwMyCs=@protonmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16879"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , Helmut Eller , Emacs Devel To: Pip Cet Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jul 02 11:38:14 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 1sOZxm-00046w-K2 for ged-emacs-devel@m.gmane-mx.org; Tue, 02 Jul 2024 11:38:14 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZx7-00024l-87; Tue, 02 Jul 2024 05:37:33 -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 1sOZx4-000242-34 for emacs-devel@gnu.org; Tue, 02 Jul 2024 05:37:30 -0400 Original-Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZx2-0004Bx-An; Tue, 02 Jul 2024 05:37:29 -0400 Original-Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-57cb9a370ddso1738679a12.1; Tue, 02 Jul 2024 02:37:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719913046; x=1720517846; darn=gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=6lF/hAAMtiOcdEIrgeqvBk6HIYONni1wnYxw05lTY0E=; b=hshZ1Oj6pUC1oEiSrVbKzKmdL7oFNkNX1+tm2P23uZH1bWibFFjkwN2iNtYY/D0x3e hMi5ryjAv5P8twQ/1H9STPD46lGz48P83YbFyx+nIR9X+P9adchN793rUevF7fyzhlQ5 VCQfNd6NSLvs44mVopJ9segIRtay41FzT6oFcJO5hEocgYuSM7UWD2epmlhsMvHFTHtF EwCzKCz4nwZzcE1ZK7ZT+sVj/Sp0SN9faccqamXiPtZ414kzOl6mq3H22QcdYrZEpXYd vsBwI5EUqZ0fLBogAf8/AEn8CAUsakG+8eNmx6keLNaF58YGawaQhX6Cksj3tCms5qvX POzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719913046; x=1720517846; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=6lF/hAAMtiOcdEIrgeqvBk6HIYONni1wnYxw05lTY0E=; b=PNjj1snWRXIn0/E8RdTuG/tX9CHIQSTmrONAz7k6oDaucb9voxX3dq32cRUwVUHyju Chjn/wD3J9H8Zhg1pVkpH5jjxRrhSR+IZ4JEORK972mmV3aCCDFjBIpruxrpLg7bv+YL tf2wDu1Nbexd8POnEIdQWc+1xGhXIibIDR1JaVBHrocc1tSmz5498nvW5RrCO04uEEj5 TJHektA6iWnY0kQon+luguu5UZEFd35P2MZxXGIbxdDPRKnItWrHNEwTX0PHsTLHqV0K KFDRxhX+5SDPFy1qe7ek230r3uuerys0MxMMT3KaYTBBoK15/keHd8bfTG9qdKjxAl+F ZB+Q== X-Forwarded-Encrypted: i=1; AJvYcCUjDGwqPUPzRCYE+HZt2V93hr90L2S4sVLjTWw5cRKjQmecwBWZuX4osARgzREry8f1lU7nY51fyfuIheSYx+U0HQI/ X-Gm-Message-State: AOJu0YyByOL2S2kHLowEUfNplLOR5mLrEJCXqIQjB0/BfVqmNmFPT9Nt OA5r6R6iDLDOzxpk166Edv7ki6+Fi5f/xeuvG0wpxEERyRMqzq4iN/7gIg== X-Google-Smtp-Source: AGHT+IErb6GRzHYsUk2hoslVlFxEycCemuFvHQN+vqSNG7cM7wWyIPwkec+PgIIUeh/R8tGaTO4pvQ== X-Received: by 2002:a17:907:2cc2:b0:a72:6055:788d with SMTP id a640c23a62f3a-a7514452aefmr695257766b.42.1719913045052; Tue, 02 Jul 2024 02:37:25 -0700 (PDT) Original-Received: from pro2.fritz.box (pd9e36129.dip0.t-ipconnect.de. [217.227.97.41]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a72ab065153sm405161666b.134.2024.07.02.02.37.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 02:37:24 -0700 (PDT) In-Reply-To: (Pip Cet's message of "Tue, 02 Jul 2024 09:15:44 +0000") Received-SPF: pass client-ip=2a00:1450:4864:20::52c; envelope-from=gerd.moellmann@gmail.com; helo=mail-ed1-x52c.google.com 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:321114 Archived-At: Pip Cet writes: > the strong part contains the hash values, next table, and index table, > and the weak part contains both the keys and the values, in a single > array of length 2 * size. See, I overlooked that! Then I think we're good :-). Thanks for explaining this. > Rather than adjusting the stride and keeping things in a single cache > line in this (slow, anyway) case, we store all keys in > weak->entries[0..table_size], and all values in > weak->entries[table_size..2*table_size]. * when MPS splats a key, we > (not MPS) splat the value before it is scanned * when MPS splats a > value, we splat the key after it has been scanned * it appears to > work: > > (setq table (make-hash-table :weakness 'key-and-value)) > > (puthash t (cons 1 2) table) > (puthash (cons 3 4) t table) > (puthash (cons 5 6) (cons 7 8) table) > > (hash-table-count table) ;; => 3 > > (igc--collect) > > (hash-table-count table) ;; => 1 > > (setq values nil) > > (igc--collect) > > (hash-table-count table) ;; => 0 > > > What confused me was the "after it has been scanned" part. I believe > that means we keep the objects alive until we scan again, but as > splatting isn't perfectly eager anyway, that should rarely become a > problem. Agree. >> Hm, maybe they are value weak? Key-weak would make no sense, I think, >> indeed. > > emacs-lisp/macroexp.el:(defvar macroexp--warned (make-hash-table :test #'equal :weakness 'key)) > emacs-lisp/map-ynp.el:(defconst read-answer-map--memoize (make-hash-table :weakness 'key :test 'equal)) > emacs-lisp/pcase.el:;; (defconst pcase--memoize-2 (make-hash-table :weakness 'key :test 'equal)) > org/org-macs.el:(defvar org-sxhash-hashes (make-hash-table :weakness 'key :test 'equal)) > > are key-weak... Hm. What haopens is that some specific key K is stored in the hash table. Lookup can use any key equal to K, but the splat happens only if K is no longer referenced. Example maybe, K is stored in some object O, and we want to lookup something related to K without always having access to O, but we want the table to also tell us when O is no longer in use. Something like that? >> From my POV, it's not a deal breaker if 32-bit systems don't work with >> igc, They still have the old GC, and 32-bit systems are kind of obsolete >> even Intel says and so on. It would be nice if we could that working of >> course. > > My concern is that Ravenbrook may get around to implementing emulation > for aarch64 or amd64. They are not very active anymore, and we could raise concerns and ask them to make that opt-in :-). >> >> Yeah, that's another point I forgot about. The trickery MPS does on >> Windows and Linux with 32-bits. The consequences of which are another >> very good reason to declare 32-bit systems as not supproted, from my >> POV. > > Oh, that's on Windows, too? I believe that might mean Eli might run > into weird bugs... I think they said somewhere it was done on Win32, but I can't find it at the moment. > Thanks again, and thanks for the asserts. Thanks to you for your work!