php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #72492 optimize copy on write when no actual write is performed
Submitted: 2016-06-25 09:00 UTC Modified: 2021-10-21 14:17 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: youwish dot spambot at nospam dot pls dot example dot org Assigned:
Status: Open Package: Performance problem
PHP Version: 7.1.0alpha1 OS: Irrelevant
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: youwish dot spambot at nospam dot pls dot example dot org
New email:
PHP Version: OS:

 

 [2016-06-25 09:00 UTC] 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...


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-10-21 14:17 UTC] cmb@php.net
The OPcache optimizer already does this for the first two; it
might make sense to optimize array_slice($foo, 0) as well.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC