Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100992 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45047 invoked from network); 30 Oct 2017 10:51:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Oct 2017 10:51:53 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain zend.com from 104.47.37.125 cause and error) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 104.47.37.125 mail-cys01nam02on0125.outbound.protection.outlook.com Received: from [104.47.37.125] ([104.47.37.125:58976] helo=NAM02-CY1-obe.outbound.protection.outlook.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C1/C6-07742-64407F95 for ; Mon, 30 Oct 2017 05:51:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=RWSoftware.onmicrosoft.com; s=selector1-zend-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=N1BQxszwqvYQg1kofWwLBM3GCh6zkeIgDnAuZMfsD5E=; b=1fLYd8SUTvDLC/cqhzrBz0sSZnH8BSA1M/pGl4m8E+xMJRGoRI6SGlQNJdSzHMDON25FhpKlicsUOeK0eO6YSKhn5YfYso/iFT5OnlL6KzPoX+O4+E5U8g4EHoSoOXgfZRfRnOTyAQi27tGhTKuC0Oy3jHeX77EwvPw16MTK0KQ= Received: from BN6PR02MB3234.namprd02.prod.outlook.com (10.161.152.32) by BN6PR02MB3235.namprd02.prod.outlook.com (10.161.152.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Mon, 30 Oct 2017 10:51:46 +0000 Received: from BN6PR02MB3234.namprd02.prod.outlook.com ([10.161.152.32]) by BN6PR02MB3234.namprd02.prod.outlook.com ([10.161.152.32]) with mapi id 15.20.0156.006; Mon, 30 Oct 2017 10:51:46 +0000 To: Sara Golemon , Nikita Popov CC: Benjamin Coutu , PHP Internals Thread-Topic: [PHP-DEV] Apply substr() optimization to array_slice() Thread-Index: AQHTTxz20/a4qJvkKEGmuNphC0E9pKL3vjIAgAAfsICAAAa+gIAEVjw+ Date: Mon, 30 Oct 2017 10:51:45 +0000 Message-ID: References: <20171027121225.2AAC95FB05@mx.zeyos.com> , In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=dmitry@zend.com; x-originating-ip: [213.21.45.232] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;BN6PR02MB3235;6:OC8bwMmDbLeSCUiDsUUubXj154MnM1NwjP/C0l1VQW86PpOSMYxSjVwRMU/6rv3ywwNKLJPIIRZZCIHUtMbPbQfvapBEi4z2tg0/5YpVeNw5C5vDb5ITlcrky+A3YNJv6LU7cnw13qLOc+IdHgCnWMuZFaFMDL81PgJtbB9faMzXXNA6rUIv9HCJcnaqSJxdqVujC07Pvjm7xvjJd9DaPeybQ/YivmCkvIddvArmqg/zLN+Xdf+qfc4Rz3UdWZtyEnn3FOV2uskBbbWXCyPJTKE3hUk1n5K/DDGYMUZ7bmDAqW/vnCKTTRrah+Dun+xLfO/rYjGVY0s4ifWDvDwBmw==;5:7BTfDaeaLbuE/+rmW3NYuqo9zinYdkbhcxIDvsjyBjmrbMxssoUyLm3fg/FDnwiLdywc573cR/nw6jKlvdl+wnILWkx5EY3TOL3Pkzk0/A031SUkPQzGT/tzIM5isUVmoJ7RHAlN7o+d2drtsyZ4mQ==;24:UgednmsxT44trcdWdM7BrHF7aMjfkAtMZ0s417LsnEGqyKZjOI/8qaCDO/rMRFX0p3XPtWFRFD9HrbfRy1ZdPCt9opoR9N/tWklikD/FTyU=;7:FhqN0g63XDtPKLAC9n5vvud6WBeEYMXaAaRBwusH+apRslT9U4Z+GHmgSbOgKoVnmJ+oQXmJfGn4lneU64kubt8Ph4Au09v/kRdxnBUDS06Eb/MjuHsXU05eNfLF5y7yKCR5B2TX+INe+3sDWJfRKEC565tJDtT/e1hY8iLkORkpihRyv05d/7SOVjko8IEcMDsEGS9Jm7DRkA0GW4qHSNVcmbLxCIVBdKxfa+5ODkA= x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: c486ee6e-3033-48e2-d3fb-08d51f8436e9 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(4534020)(4602075)(2017052603199);SRVR:BN6PR02MB3235; x-ms-traffictypediagnostic: BN6PR02MB3235: x-exchange-antispam-report-test: UriScan:(158342451672863); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(100000703101)(100105400095)(3231020)(3002001)(93006095)(93001095)(10201501046)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123560025)(20161123558100)(20161123555025)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:BN6PR02MB3235;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:BN6PR02MB3235; x-forefront-prvs: 0476D4AB88 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(346002)(39830400002)(199003)(24454002)(189002)(3846002)(6246003)(33656002)(3280700002)(229853002)(3660700001)(39060400002)(106356001)(102836003)(105586002)(55016002)(99286003)(74316002)(189998001)(7736002)(53936002)(8936002)(54356999)(76176999)(50986999)(6116002)(97736004)(81166006)(9686003)(54896002)(6306002)(101416001)(2950100002)(8676002)(81156014)(236005)(2906002)(7696004)(606006)(53546010)(16799955002)(14454004)(966005)(478600001)(110136005)(54906003)(66066001)(2900100001)(93886005)(316002)(6506006)(6436002)(86362001)(77096006)(68736007)(5660300001)(4326008)(25786009);DIR:OUT;SFP:1102;SCL:1;SRVR:BN6PR02MB3235;H:BN6PR02MB3234.namprd02.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: zend.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: multipart/alternative; boundary="_000_BN6PR02MB3234032488352B1AE6E99C48BF590BN6PR02MB3234namp_" MIME-Version: 1.0 X-OriginatorOrg: zend.com X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Oct 2017 10:51:45.9293 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 32210298-c08b-4829-8097-6b12c025a892 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR02MB3235 Subject: Re: [PHP-DEV] Apply substr() optimization to array_slice() From: dmitry@zend.com (Dmitry Stogov) --_000_BN6PR02MB3234032488352B1AE6E99C48BF590BN6PR02MB3234namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable The optimization also broke Zend/tests/bug72598.phpt and Zend/tests/bug7259= 8_2.phpt ________________________________ From: php@golemon.com on behalf of Sara Golemon Sent: Friday, October 27, 2017 7:34:15 PM To: Nikita Popov Cc: Benjamin Coutu; PHP Internals; Dmitry Stogov Subject: Re: [PHP-DEV] Apply substr() optimization to array_slice() On Fri, Oct 27, 2017 at 12:10 PM, Nikita Popov wrote= : > On Fri, Oct 27, 2017 at 4:16 PM, Sara Golemon wrote: >> >> On Fri, Oct 27, 2017 at 8:12 AM, Benjamin Coutu >> wrote: >> > Now, array_slice() could be optimized similarly, but currently >> > (unless the resulting array is expected to be empty) we always >> > create a new array no matter if we actually have to. >> > >> Pushed, with an additional escape hatch for vector-like arrays (which >> are implicitly like preserve_keys). In the future though, please use >> the PR process. Thanks. > > > Unfortunately these optimizations are subtly incorrect in the current for= m, > because arrays have a bunch of additional hidden state. See > https://bugs.php.net/bug.php?id=3D75433 for a (not yet fixed) issue that > resulted from similar optimizations in 7.2. We'll have to review all the > places where we apply optimizations like these and make sure that we're n= ot > introducing incorrect behavior wrt the next free element or internal arra= y > pointer. > It took awhile to unwind the repro case given in the bug report, but this seems to be a simpler example: https://3v4l.org/rqphD Basically, that next insert index for the output of array_values() should be reset, and with the optimization it's not. For array_values() the quick and dirty fix is adding "&& nextIndex =3D=3D num_elements" psuedocode. In the case of array_slice, the same will be true, so I agree we should be careful about applying such optimizations. I'll clean up these uses now, and would suggest something like: zend_array* zend_hash_duplicate(zend_array* input, zend_bool preserve_keys); type API which can be a certral place for making that kind of short-circuit versus slow-copy decision when called from places like array_values() and array_slice(). -Sara --_000_BN6PR02MB3234032488352B1AE6E99C48BF590BN6PR02MB3234namp_--