Req #72492 [Opn]: optimize copy on write when no actual write is performed

From: Date: Thu, 21 Oct 2021 14:17:39 +0000
Subject: Req #72492 [Opn]: optimize copy on write when no actual write is performed
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237324@lists.php.net to get a copy of this message
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)

« previous php.bugs (#237324) next »