Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108190 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 2079 invoked from network); 18 Jan 2020 01:11:53 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Jan 2020 01:11:53 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 87E471804F2 for ; Fri, 17 Jan 2020 15:19:39 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS8075 40.64.0.0/10 X-Spam-Virus: No X-Envelope-From: Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10olkn2068.outbound.protection.outlook.com [40.92.42.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 17 Jan 2020 15:19:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V1Kk4CVKsUCcbjTOefqZyQXtGOFWWxk3MV24+wTb0ZV60FN8LPKGg4qLdkkMPRnFY2IIUossnn906WOPTkYGnsUP0nsGj3lr9D5+Op396+FiLFOjSaDm+SQ0Dsmls0UB5cpValVHcujhjknuC9YoeaHaYULlniqaYFADIcVcP4tepYeaMg+1JzhiQGJr7F3C22zHTQqgtREymybTV9II/LgwzWed64SGZvfxAmzch4wnsaJMfuO+nlRP19aqeVibilbgBcrexsBO3hNL9GNAYEtGdFn4KxlZ8BBR0YtqzTbGauFdTDDLba/1VjPN0jKft95ZWs8D/pIhhDlmcKkN/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8V1JHzkTfZbrue7ksaMj8Rsx16rdxzfNVIQ8j8zN1YA=; b=Q4ShcSfQqjARvTFHWZ9vke6UkRgCXAfc0j/L83hg0PkG7WfRSg4Jl+TzDHGEKZx3grmpwpNj3t8i9HrKzFmMHoo7ssCy9vsh3iXLICU19h/q2pTAPdvsSdqdWlHe9NYi52ev/Zcd6TUBAyMWJwlJHeJwHcTq501lPwVLR9PGSrb52RtGsLCIIhh/1WE0PvC/q7tyaC8cctqRvfSEVmxQZXZvbnuH5+oXuAoMclVdE63Ndo8hO5mCtzGTEiUz9FJBZl/fKEEqfVU70qthNPoc5vABUHv6sDTqpN7BmbAz3UNK7qmruQQeN9kowKOLYO/MRpDZvyvYbgbknCk12WLnyg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8V1JHzkTfZbrue7ksaMj8Rsx16rdxzfNVIQ8j8zN1YA=; b=lHxTGqaBew8pIJr2EyUco9e19olFI2TtSSN0VVSGmB6wu5aBiDK8T4P38B0orf59BjoBL7Mf0RYQwp0GDMEB/xyGPmhUQUXQsgyS/wM0ukLY2oYUbEC/6Fifsnc5XDQ2N15UzJVJO3DHOdmtMRJejhXusE5nxBL7S9zbULzFp4satCEPB1eQD3lq4lwJ0gcoVnPS3FvTlRNvGvG8hux5gYFKYPnIyLTmOjb1oMVvFjp9azyy73gdxy4RWbWXg+FyeALyQ4xGcI5xYW3LesFveRaRbKTIn9ebdIB59hfCk+1inutNRzJnOaCKAjJ3MzwQGdMma8VTr3EHhpN7H0vPvg== Received: from MW2NAM10FT005.eop-nam10.prod.protection.outlook.com (10.13.154.60) by MW2NAM10HT088.eop-nam10.prod.protection.outlook.com (10.13.155.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.19; Fri, 17 Jan 2020 23:19:37 +0000 Received: from DM5PR07MB3067.namprd07.prod.outlook.com (10.13.154.53) by MW2NAM10FT005.mail.protection.outlook.com (10.13.154.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.19 via Frontend Transport; Fri, 17 Jan 2020 23:19:37 +0000 Received: from DM5PR07MB3067.namprd07.prod.outlook.com ([fe80::29e3:53bf:163e:5beb]) by DM5PR07MB3067.namprd07.prod.outlook.com ([fe80::29e3:53bf:163e:5beb%3]) with mapi id 15.20.2644.023; Fri, 17 Jan 2020 23:19:37 +0000 To: Aran Reeks , Mike Schinkel , Nikita Popov CC: PHP internals Thread-Topic: [PHP-DEV] Typed array properties V2 Thread-Index: AQHVzQrpe+Ij2B4DWk657/xGAa3nLKfvO1mAgAAH8wCAADUnPA== Date: Fri, 17 Jan 2020 23:19:37 +0000 Message-ID: References: , In-Reply-To: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:2CD19BA2B6A59D8334484D8E3FED37827F745A9BFBF8B1B33DA67BADB905F4F2;UpperCasedChecksum:34A9CBA48CD3C82BCCE9D68DC906AA422D29CD823D6017E8B72DF9D1020A2C80;SizeAsReceived:7177;Count:46 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [ze3PtLEIMfyreKtKNZ7dRfFP3KWSGLsp] x-ms-publictraffictype: Email x-incomingheadercount: 46 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: d64fe696-7c73-49f2-d881-08d79ba3b865 x-ms-traffictypediagnostic: MW2NAM10HT088: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: YBKOn/rCKTY5S2CktRlk6+Qwm6zGHDkaxV3KZ3KjNs6xzGfw3/6EuycAIgp12Mz7H2gPQrp37O3Fi7urnA08PWAbnLASuQ/6xHKVjSrLTjEAUN74FMuTAofvxYnZ0/+zpzUZ1/XKw01pbMRb8LcPLSzu0dY9knWVRVeGD6vnrm4QqkV9F2zbs+dnO2jXY1uMBeW+uTfi6RqiOZksyuZNUG/Y8v9fj1eEo07iKbCI0kc= x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: d64fe696-7c73-49f2-d881-08d79ba3b865 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jan 2020 23:19:37.0871 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2NAM10HT088 Subject: Re: [PHP-DEV] Typed array properties V2 From: tysonandre775@hotmail.com (tyson andre) > I'm unsure of exactly how this might work so defer to an Internals export= ,=0A= > but having previously read @Nikita Popov 's great= =0A= > post on PHP's arrays, I did wonder if by knowing the data type within an= =0A= > array and that it'd conform to a strict structure, could the array itself= =0A= > be stored in an alternative way in C? Perhaps a more memory efficient way= ,=0A= > or one that's faster to iterate over rather than just a hash table?=0A= =0A= > Link to this article for reference:=0A= > https://nikic.github.io/2012/03/28/Understanding-PHPs-internal-array-impl= ementation.html=0A= =0A= A significant improvement that could be made to memory efficiency is to red= uce the minimum array size for *dynamically* created arrays.=0A= Currently, it's always 8 and must be a power of 2, even if there's only one= element or the array is packed (i.e. a list without gaps)=0A= - Array constants cached in opcache already have this optimization.=0A= =0A= I have a PR that reduces the minimum size to 2 - the largest blockers were = getting a realistic idea of whether commonly used applications=0A= would see a decrease or increase in runtime, and needing code review.=0A= ("I'd want to know how this would be benchmarked before adding more changes= , in case additional optimizations somehow turn out to be a performance reg= ression.")=0A= =0A= > For example, Phan's memory usage for self-analysis (./phan --print-memory= -usage-summary)=0A= > went from 444MB/576MB to 387MB/475MB (end memory/max memory) with this pa= tch.=0A= > (This is a static analyzer for PHP which heavily uses small arrays)=0A= =0A= ----=0A= =0A= > I did wonder if by knowing the data type within an=0A= > array and that it'd conform to a strict structure=0A= > could the array itself be stored in an alternative way in C?=0A= =0A= It might theoretically be possible to optimize the memory of an `int[]` (64= bits per element) without references or gaps in elements.=0A= If a reference in an element got added, or it stopped being a packed array = without gaps (i.e. a list),=0A= then such an implementation would use an unoptimized version that also enfo= rces the type constraint=0A= (128 bits per list element with zvals).=0A= It would probably require changing a lot of APIs and macros, and I'd have n= o idea how to implement it.=0A= =0A= I think JavaScript engines do something similar by having specializations f= or JS arrays of integers,=0A= arrays of floats, arrays of small (e.g. 16-bit) integers, etc.=