|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
[2021-07-12 11:25 UTC] cmb@php.net
-Assigned To:
+Assigned To: cmb
[2021-07-12 11:25 UTC] cmb@php.net
[2021-07-12 16:39 UTC] git@php.net
[2021-07-12 16:39 UTC] git@php.net
-Status: Assigned
+Status: Closed
[2021-09-06 17:02 UTC] nospam at briat dot org
[2021-09-06 17:13 UTC] cmb@php.net
[2021-09-06 17:45 UTC] nikic@php.net
[2021-09-07 17:12 UTC] nospam at briat dot org
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 15:00:01 2025 UTC |
Description: ------------ The string returned by preg_replace uses too much memory - multiples of the actual string size in bytes. For big strings, this can be a significant performance issue. mb_ereg_replace does not have this problem. When I copy the returned string using some of the PHP string functions, the storage size is reduced in case the memory for the string is reallocated. Test script: --------------- $base_memory = memory_get_usage(); $test_string = str_repeat('Eins zwei drei', 2000); var_dump(memory_get_usage() - $base_memory); $replaced = preg_replace('/\s/', '-', $test_string); var_dump(memory_get_usage() - $base_memory); $replaced = str_repeat($replaced, 1); #$replaced = str_replace('e', 'e', $replaced); #$replaced = $replaced[0] . substr($replaced, 1); var_dump(memory_get_usage() - $base_memory); Expected result: ---------------- int(28672) int(57728) int(57728) Actual result: -------------- int(28672) int(106880) int(57728)