Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102119 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61709 invoked from network); 18 May 2018 12:17:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 May 2018 12:17:49 -0000 Authentication-Results: pb1.pair.com smtp.mail=ekneuss@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=colder@php.net; sender-id=unknown Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.193 as permitted sender) X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 209.85.223.193 mail-io0-f193.google.com Received: from [209.85.223.193] ([209.85.223.193:34936] helo=mail-io0-f193.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 25/62-13666-C64CEFA5 for ; Fri, 18 May 2018 08:17:49 -0400 Received: by mail-io0-f193.google.com with SMTP id g1-v6so5918457iob.2 for ; Fri, 18 May 2018 05:17:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=CB2BU3cJRFUN8TAqDAnnbkM83iqrr9ICJXLUDmpootw=; b=qJbeqb/the2njWtm5NEQsuk9uqRRDYhbSW3rlk18kqi3jaVjOVp5cAEZWp6xXBzePb T27LffKilKsZNU79INb7McfG8Z74VSR6HBpmNUwSRTBrE4bIQNMTTFIIM4jES0ki29An rr2w6T09HD7q3yY1oJvdtAkXfOv4BjR4IJEPTbC+vQHnwiRSnrqoWByDMulu0MJSGBos 6jbPUFdAhjF+Toe1qWajXYMT0uENqqfzpUZjKRtLdUrbEzoVU2mFMBMWNsKZyLrxZZVo +wYlCFHx5M0XOVol9HSFhnzPqwwVLkA/0HcT+pVTF1kCuP6XofV5/SodUG3NI2WhvtyT KOLg== X-Gm-Message-State: ALKqPwe6dIWcpOIucKux6JoTIi7JJ1q1okC0CMBCF31kh0bV6rB9332v ET+Nxm4MtopzDJ3hiuxr1pPv2f9vrodWrqVq0HjwWukA X-Google-Smtp-Source: AB8JxZq/dI6OTixor/tYKQbHJZv+CIZXnKHDWeKoaXPE9WTh5+MZdgRf5zjo/NXHVl2XR2g1kcsxWqQ6lyqfZuNTmxU= X-Received: by 2002:a6b:bc06:: with SMTP id m6-v6mr9685279iof.205.1526645865635; Fri, 18 May 2018 05:17:45 -0700 (PDT) MIME-Version: 1.0 References: <47A0DB53-F5B8-4A3E-8288-28154A342ED9@gmail.com> In-Reply-To: <47A0DB53-F5B8-4A3E-8288-28154A342ED9@gmail.com> Date: Fri, 18 May 2018 14:15:21 +0200 Message-ID: To: internals Mailing List Content-Type: multipart/alternative; boundary="00000000000084e3cc056c79f007" Subject: Re: [PHP-DEV] RFC WeakRefs From: colder@php.net (Etienne Kneuss) --00000000000084e3cc056c79f007 Content-Type: text/plain; charset="UTF-8" On Fri, May 18, 2018 at 1:59 PM Rowan Collins wrote: > On 17 May 2018 10:35:11 BST, Etienne Kneuss wrote: > >That said, if the plan is to subsume pecl-weakref, I suggest we also > >reimplement weakmaps, which offer a convenient way of storing > >meta/cache > >data and is not implementable in userland without trade-offs. > > It looks to me like WeakMap would be fairly trivial to implement in > userland as a combination of WeakRef, ArrayAccess, Iterable, and an > internal SplObjectStorage for the ability to use objects as keys (although > I'm not clear why it uses object keys in the first place). > In weakmaps it is the keys that are weak, hence objects only; the values are arbitrary data associated with them. The goal is to provide a way to associate metadata that may also be collected in case the key gets collected. In some sense it would behave as if this metadata was stored as a property of the object, only it is stored externally in a weakmap. > > >> The only part that seems hard to write efficiently is Countable support, >> since you'd have to iterate the internal hash checking for unset objects. I >> suppose iteration would also slow down a bit of lots of the references were >> now unset. Is that the trade-off you're referring to, that the C >> implementation has some magic to avoid? >> > You indeed would need a O(n) count. But it's not the only issue: you also should DELREF the values associated with invalid weakrefs once in a while, and doing this manually makes this entire thing less attractive. --00000000000084e3cc056c79f007--