Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54389 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10478 invoked from network); 4 Aug 2011 20:53:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Aug 2011 20:53:47 -0000 Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.42 as permitted sender) X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 209.85.218.42 mail-yi0-f42.google.com Received: from [209.85.218.42] ([209.85.218.42:62109] helo=mail-yi0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 87/30-08937-9D60B3E4 for ; Thu, 04 Aug 2011 16:53:46 -0400 Received: by yie19 with SMTP id 19so186068yie.29 for ; Thu, 04 Aug 2011 13:53:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=gGySRQGRlAbwskqIKSVyN7UDA/kOhOopAwaGT8ivjGw=; b=vF6Y7xza08eT+Becf/xe5ZLd6KGaBwc8u7kRXQ0MrKdmNYrKm8nqmas6sKvxIo+/Hn gF4qStXg5L7xMQjOO/iYyau9hYC13vnO+wv6qB/nBPwhYTfiSj+d6zAzaXKn6PeZHH00 2bWN6H1/4ZKDvhF69PFhORlo2qYDEkQW5AsWM= MIME-Version: 1.0 Received: by 10.236.190.234 with SMTP id e70mr1846952yhn.202.1312491222468; Thu, 04 Aug 2011 13:53:42 -0700 (PDT) Received: by 10.147.82.17 with HTTP; Thu, 4 Aug 2011 13:53:42 -0700 (PDT) In-Reply-To: <4E3ACA42.8000001@sugarcrm.com> References: <4E3898B0.40809@sugarcrm.com> <4E38EC0C.9080304@lerdorf.com> <4E38FA2E.4030605@lsces.co.uk> <4E38FC67.9090200@toolpark.com> <4E39E89F.8060605@sugarcrm.com> <4E3A3643.2070305@toolpark.com> <4E3A4793.2070209@sugarcrm.com> <4E3A91E8.1020107@toolpark.com> <4E3ACA42.8000001@sugarcrm.com> Date: Thu, 4 Aug 2011 22:53:42 +0200 Message-ID: To: Stas Malyshev Cc: Lars Schultz , "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [VOTE] Weak References From: tyra3l@gmail.com (Ferenc Kovacs) On Thu, Aug 4, 2011 at 6:35 PM, Stas Malyshev wrot= e: > Hi! > On 8/4/11 5:34 AM, Lars Schultz wrote: >>> >>> Do not keep object references, keep object IDs. This would make your >>> code a bit more verbose and a bit slower, but weak refs would >>> essentially do the same anyway. >> >> This is like saying: do not use objects at all and use the DB for >> storage. verbosity and slowness is something I'd like to prevent. > > No, it's not even remotely like that. Using one intermediary function and > doing the DB call is orders of magnitude apart. You asked how you can sol= ve > the problem, I showed you how. You can claim you don't like the solution, > that's fine, everybody has his own taste. But you can't claim there's no > other solution. maybe it's just me, but I not fully understand your solution. "I'm not sure I understand why you need week refs there - can't you just always use $prodDb->getProduct(1) and when you don't need it anymore just do $prodDb->drop(1)? Or let it drop it whenever it wants to?" "Do not keep object references, keep object IDs. This would make your code a bit more verbose and a bit slower, but weak refs would essentially do the same anyway." from that, my guess is that you propose that nobody should hold a reference for the product, but always use the returned object from getProduct() on the fly. you also suggest that ProductDatabase should also remove the cached object when appropriate. did I get interpreted your solution correctly? I have some problems with this approach: - you cannot guarantee/force the contract that the result of the getProduct cannot be stored. - in a loosely coupled system, it is hard to tell when "you don't need it anymore". as you and Lars both mentioned we only care about freeing the cache, because we have memory constraint. Lars mentioned that currently he manually checks the memory usage, and free the cache if needed: http://www.mail-archive.com/internals@lists.php.net/msg52423.html of course one could also write some algorithm, which removes records from the cache either randomly, or as Jonathan suggestion doing something like LRU/MRU. with Weak References, you shouldn't care about that, the gc would do it for your, albeit in a less sophisticated way: if the gc root buffer is full, then free every item which isn't used at that time. and of course you can combine the WeakRefs and some cache algorithm as Jan did in his blogpost. (good article btw. and also good to see that Benjamin Eberlei from the Doctrine project looking into the possible use cases for them) so as I see you didn't really addressed the proposed use-case of the Weak References, just stated what everybody is aware of: one can cache and free objects "manually" without the need of Weak References. and while that is true, I still think that this could be a great asset for creating high quality components. as we agreed that this won't be considered for inclusion to the core but released as a pecl extension, I think that we should update the RFC accordingly and close the vote. we will see what happens when people start using and experimenting with it. btw. it was suggested before, but I really think, that it would be a good idea to have a register_ function which would allow you to pass a callable, which will be called when the memory usage reaches a given value. that would make a good addition to resolve some of use cases mentioned in this thread. --=20 Ferenc Kov=C3=A1cs @Tyr43l - http://tyrael.hu