Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96929 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54387 invoked from network); 16 Nov 2016 15:47:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Nov 2016 15:47:15 -0000 Authentication-Results: pb1.pair.com header.from=michal.brzuchalski@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=michal.brzuchalski@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.47 as permitted sender) X-PHP-List-Original-Sender: michal.brzuchalski@gmail.com X-Host-Fingerprint: 74.125.82.47 mail-wm0-f47.google.com Received: from [74.125.82.47] ([74.125.82.47:38399] helo=mail-wm0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 67/33-05303-18F7C285 for ; Wed, 16 Nov 2016 10:47:13 -0500 Received: by mail-wm0-f47.google.com with SMTP id f82so81597552wmf.1 for ; Wed, 16 Nov 2016 07:47:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=VPOWxdDNxTYAddKJESjn+FZfXU4pLkGgl89zpMkPtc0=; b=FrRXdXESXFsgY9rduMTvy9Id8RRDNBjwnza5CjAEltIr7QlNkbM4EEI/RVeL6bs4aP zIi7cYnKaxtfwUii+8C0E6k9GJWX+oMgW6tw0sBBL8gasmslOrH4qg/vNRDp+AIg79IA 4lYvPP6kSxmSzLlkhn6+EvhAtbEPeTM9z/gbyePDhW1Kz9I/ye5t580k0xFmWubPfCrI aQU/6WhZ6XuKo3twamzIh08vuqpEEhbfX+ocXeb8gw31kopzKAxzfBuyvL0asTKrddZD OL34OEJapnAsW3GdkgKKLqEzKopbZG52x8oNcZvr9Jtk9S1I4TXvyobdZQ8JkmEImv/A pEwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=VPOWxdDNxTYAddKJESjn+FZfXU4pLkGgl89zpMkPtc0=; b=lOTp5iYWqihnooxucOnpPgOYYzS8hbLjOmdiOc1nSy0YoNYFSnqJPIpWQB61qRwSp9 S991GQPLd3ByEAuePZz3YlzhbQDYE18q1Yz4JbsueuV54ZMWBYr72pOWzlSNKv4M/a7m YRwy5Fz1PCw2PDPsn3k8qGvrbAaJzP1/FrVlp79tS8Q4bbiJLnCetu3CacJOsvwsRlz9 ZyFN9lZ/3mnkmiHJVoERcySQbnODyoPo5FMoxWAF2Vn2u8mcX1vXLUNMIWgCM9cnxwmy 1pxa7NAzIvNqf9ma8/nm8YJ7gTPin1YzGPgEvemE1VvNSqtuSVsPFCjixAsqbrMxIDGP zD6A== X-Gm-Message-State: ABUngvc27jTek9f3fdYSMDd6LEQWziFm4pM13YKSo9LLvbGh3VsoiXkmeclJUSHCD2CiC6J6VyJ4jG+bFaPcrg== X-Received: by 10.194.243.231 with SMTP id xb7mr2826948wjc.60.1479311229829; Wed, 16 Nov 2016 07:47:09 -0800 (PST) MIME-Version: 1.0 Received: by 10.28.103.10 with HTTP; Wed, 16 Nov 2016 07:47:08 -0800 (PST) Received: by 10.28.103.10 with HTTP; Wed, 16 Nov 2016 07:47:08 -0800 (PST) In-Reply-To: References: Date: Wed, 16 Nov 2016 16:47:08 +0100 Message-ID: To: David Rodrigues Cc: PHP Internals List , =?UTF-8?Q?Silvio_Mariji=C4=87?= Content-Type: multipart/alternative; boundary=089e01493e645dcf5305416cfcf8 Subject: Re: [PHP-DEV] Immutability RFC From: michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --089e01493e645dcf5305416cfcf8 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 16.11.2016 16:39 "David Rodrigues" napisa=C5=82(a)= : > > 2016-11-16 11:57 GMT-02:00 Silvio Mariji=C4=87 = : > > If we treat those objects as values then this should return true. But then > > again there might be some confusion because then two operators are doin= g > > the same thing. Maybe throw an error ? Suggestions ? > > I just thinking about "how it will be done"? > I imagine that we should store all calling to memory, then I see two > problems for this case: > > 1. High memory consumption: all immutable objects should be stored on > memory eternally (or until the script ends). I mean: if I call it a > hundred times with differents parameters, I'll have a hundred of used > memory, that will avoid any used variables of be GC (once that it > should stores it for references). > All instances are GC the same as nornal classes when unneeded any longer. > 2. High CPU consumption: every time that I instantiate an immutable > class, the engine will loop on each possibilities and check if all > parameters match to then return the same object (or then, create a > new). Then the major question for it is: should all parameters of an > immutable constructor be considered on instantiate? Should I pass the > exactly copy (read "reference") of object to the parameter to return > the same instance or a "shallow copy"? > There is no cache - each immutable objects is created the same as normal object except it won't let you pass references. > For both problems above, I guess that a "factory pattern with cache" > should works better, once that I could consider the exact value where > it requires to be immutable, and I could cache only if it is really > required, for instance: > > class SomeFactory { > private static $cache =3D []; > > public static function getType(Type $type) { > if (!$type->shouldBeCache()) { > // Code flexibility... > return new self($type); > } > > if (!array_key_exists($type->id, self::$cache) { > self::$cache[$type->id] =3D new self($type); > } > > return self::$cache[$type->id]; > } > } > > > -- > David Rodrigues > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > --089e01493e645dcf5305416cfcf8--