Req #72492 [Opn]: optimize copy on write when no actual write is performed
Edit report at https://bugs.php.net/bug.php?id=72492&edit=1
ID: 72492
Updated by: cmb@php.net
Reported by: youwish dot spambot at nospam dot pls dot example
dot org
Summary: optimize copy on write when no actual write is
performed
Status: Open
Type: Feature/Change Request
Package: Performance problem
Operating System: Irrelevant
PHP Version: 7.1.0alpha1
Block user comment: N
Private report: N
New Comment:
The OPcache optimizer already does this for the first two; it
might make sense to optimize array_slice($foo, 0) as well.
Previous Comments:
------------------------------------------------------------------------
[2016-06-25 09:00:01] youwish dot spambot at nospam dot pls dot example dot org
Description:
------------
Not very important, I'm dropping this findings here so they don't get lost in the meanders
of web.
These operations (and similar ones) don't require a copy to be performed as the result is
identical to the original.
Test script:
---------------
$foo = str_repeat('foo', 100000);
var_dump(memory_get_usage());
$baz = '' . $foo; // $baz is identical to $foo
var_dump(memory_get_usage());
unset($foo, $baz); echo "\n";
$foo = array_fill(0, 1000, 'foo');
var_dump(memory_get_usage());
$baz = array_merge($foo, []); // $baz is identical to $foo
var_dump(memory_get_usage());
unset($foo, $baz); echo "\n";
$foo = array_fill(0, 1000, 'foo');
var_dump(memory_get_usage());
$baz = array_slice($foo, 0); // $baz is identical to $foo
var_dump(memory_get_usage());
// etc...
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72492&edit=1
Thread (2 messages)