Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116267 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 71162 invoked from network); 13 Oct 2021 07:19:31 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Oct 2021 07:19:31 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2D92A18037E for ; Wed, 13 Oct 2021 01:05:56 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 13 Oct 2021 01:05:55 -0700 (PDT) Received: by mail-ed1-f42.google.com with SMTP id z20so6457445edc.13 for ; Wed, 13 Oct 2021 01:05:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Ap0jMJOzdsQfnbxBW+P7GHW5VWYcFQwBjPREaPM76TM=; b=GY9MvhUCNMYenlijHjACoHto1UuTWBw8XSvOMmPHdtIHXCH0zyEt2xdDK0lkr6Ap0V BMDra1aq7GozLlYE5c9ZvjNfKam9VZh0O9TaNAyGnMetRI7L87GmU7QU9nYxYvHjxsi6 2cVw7kXRFZKlFsksknwdKDEYmpFLMsdvWVR1QHKTQunPQUaKcVtHGJsZ8ldwn4SIOsQT j9P9L7lXZx0qtV+NZ89xsMugomEYIoyNnrZReT5mhuAH8TvimdR5ihgoLS8X9OHrq3kr Z0+gAtHQKzXIOOukT9BPyxo/5brAnBAmfq8LfM/wwkn+Zy3Id+h2OWO/jLh/NHcBV+Bj Lkxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Ap0jMJOzdsQfnbxBW+P7GHW5VWYcFQwBjPREaPM76TM=; b=ZvbRYOpWELX6YcoC/7sQhNzvk9xmfpCgSYZLoF9ft1CV4f3xJ3kR7GWAWQ5E6qZWSb qBY3eM4Vl44TILTb1XcQhT9N6R+HG7Y04KBIx6my81XYdM/WbH/V2tiib6ooX+an4c/K EDtpI02u5Wyeaoe2EsWSAL6Y4S5KPdP89+KZFgVnYUlvM01ztcWT1/foUtLty+UcByGo TXLQsUIdQUe8+ZsZkTjaMwJr6F8Zyof4W2waueZaixDyyyY+vQAGKayIhaJ5+Nhwr1Wm CWKLGxp/5vwnU2wx4oYkyFqKhyKBTwhW5N8wdsG6zkBUaDKYP4mSyg00zz7qJTugDC3s Lb2Q== X-Gm-Message-State: AOAM530NPGM7hz7ELxE5ukqh2m1BPdVN61hivtab+13fXtVgjB2737sf XVgYxX0GDCt0p2XcA+YgJvdc6OD0MWEjdhAo8F8= X-Google-Smtp-Source: ABdhPJwgNTKFkfVurL1EbUoZ4ryr0X3b7BeSjgAhgePYXA5+i+ElWV/eYNxuykGOlCURgZ73nCsbLu4X/1YdV6U3os4= X-Received: by 2002:a17:906:bfe3:: with SMTP id vr3mr38880709ejb.339.1634112352757; Wed, 13 Oct 2021 01:05:52 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 13 Oct 2021 10:05:36 +0200 Message-ID: To: Tim Starling Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000004f2ac405ce376e53" Subject: Re: [PHP-DEV] Re: [RFC] Deprecate dynamic properties From: nikita.ppv@gmail.com (Nikita Popov) --0000000000004f2ac405ce376e53 Content-Type: text/plain; charset="UTF-8" On Wed, Oct 13, 2021 at 3:43 AM Tim Starling wrote: > On 12/10/21 9:23 pm, Nikita Popov wrote: > > Based on the received feedback, I've updated the RFC to instead provide > an > > #[AllowDynamicProperties] attribute as a way to opt-in to the use of > > dynamic properties. As previously discussed, this won't allow us to > > completely remove dynamic properties from the language model anymore, but > > it will make the upgrade path smoother by avoiding multiple inheritance > > issues. Especially given recent feedback on backwards-incompatible > changes, > > I think it's prudent to go with the more conservative approach. > > I think it would still be the biggest compatibility break since PHP > 4->5. Adding a custom property is a common way for an extension to > attach data to an object generated by an uncooperative application or > library. > > As the RFC notes, you could migrate to WeakMap, but it will be very > difficult to write code that works on both 7.x and 8.2, since both > attributes and WeakMap were only introduced in 8.0. In MediaWiki > pingback data for the month of September, only 5.2% of users are on > PHP 8.0 or later. > Just to be clear on this point: While attributes have only been introduced in 8.0, they can still be used in earlier versions and are simply ignored there. It is safe to use #[AllowDynamicProperties] without version compatibility considerations. > Also, in the last week, I've been analyzing memory usage of our > application. I've come to a new appreciation of the compactness of > undeclared properties on classes with sparse data. You can reduce > memory usage by removing the declaration of any property that is null > on more than about 75% of instances. CPU time may also benefit due to > improved L2 cache hit ratio and reduced allocator overhead. > Huh, that's an interesting problem. Usually I only see the reverse situation, where accidentally materializing the dynamic property table (through foreach, array casts, etc) causes issues, because it uses much more memory than declared properties. Based on a quick calculation, the cost of having dynamic properties clocks in at 24 declared properties (376 bytes for the smallest non-empty HT vs 16 bytes per declared property), so that seems like it would usually be a bad trade off unless you already end up materializing dynamic properties for other reasons. Did you make sure that you do not materialize dynamic properties (already before un-declaring some properties)? > So if the point of the RFC is to eventually get rid of property > hashtables from the engine, I'm not sure if that would actually be a > win for performance. I'm more thinking about the need for a sparse > attribute which moves declared properties out of properties_table. > The ability to opt-in to dynamic properties would always remain in some form (if only through stdClass extension as originally proposed), so if you have a case where it makes sense, the option would still be there. Regards, Nikita --0000000000004f2ac405ce376e53--