From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 03705158089 for ; Thu, 21 Sep 2023 15:47:16 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 29FDF2BC0D3; Thu, 21 Sep 2023 15:47:15 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 120D72BC0D3 for ; Thu, 21 Sep 2023 15:47:15 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 3A53C335CE3 for ; Thu, 21 Sep 2023 15:47:14 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id AF91BF4B for ; Thu, 21 Sep 2023 15:47:12 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1695311160.c6ee4348df65210ee4c052b894cbc9f4f54f6ce8.sam@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: lib/_emerge/ X-VCS-Repository: proj/portage X-VCS-Files: lib/_emerge/depgraph.py X-VCS-Directories: lib/_emerge/ X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: c6ee4348df65210ee4c052b894cbc9f4f54f6ce8 X-VCS-Branch: master Date: Thu, 21 Sep 2023 15:47:12 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 0fb7a794-bf3b-47b2-9e73-560c2e2495f8 X-Archives-Hash: de5b2ab597baad276ed4ce091eba4244 commit: c6ee4348df65210ee4c052b894cbc9f4f54f6ce8 Author: Daniel Harding living180 net> AuthorDate: Sun Sep 10 06:51:13 2023 +0000 Commit: Sam James gentoo org> CommitDate: Thu Sep 21 15:46:00 2023 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=c6ee4348 depgraph: improve reverse dep caching Avoid applying @functools.lru_cache() to the depgraph._slot_operator_check_reverse_depencencies() method, as applying the lru_cache decorator to a method can prevent the class instances from being garbage collected due to self being stored in the cache as part of the args key[1]. Instead, set up a per-instance cache in the __init__() method. [1] https://stackoverflow.com/q/33672412/3573385 Bug: https://bugs.gentoo.org/883071 Signed-off-by: Daniel Harding living180.net> Signed-off-by: Sam James gentoo.org> lib/_emerge/depgraph.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/_emerge/depgraph.py b/lib/_emerge/depgraph.py index 01a49bcb53..0629acab22 100644 --- a/lib/_emerge/depgraph.py +++ b/lib/_emerge/depgraph.py @@ -679,6 +679,12 @@ class depgraph: self.query = UserQuery(myopts).query + # Set up a per-instance memoization cache for the + # _slot_operator_check_reverse_dependencies() method: + self._slot_operator_check_reverse_dependencies = functools.lru_cache( + maxsize=100 + )(self._slot_operator_check_reverse_dependencies) + def _index_binpkgs(self): for root in self._frozen_config.trees: bindb = self._frozen_config.trees[root]["bintree"].dbapi @@ -2214,7 +2220,8 @@ class depgraph: return None - @functools.lru_cache(maxsize=100) + # This method is memoized on a per-instance basis via a decorator applied + # in __init__(). def _slot_operator_check_reverse_dependencies( self, existing_pkg, candidate_pkg, replacement_parent=None ):