Opened 2 years ago

Last modified 23 months ago

#16794 new enhancement

pomo/streams.php str_split() suggestion ?

Reported by: mrasnika Owned by:
Priority: normal Milestone: Awaiting Review
Component: Performance Version: 3.1
Severity: minor Keywords: close
Cc:

Description

Hi, just passing along an idea that was suggested to me: we have a log which crashes with this --

Fatal error: Out of memory (allocated 23855104) (tried to allocate 9 bytes) in /var/www/html/wp-includes/pomo/streams.php on line 86

If you look at that line:

http://core.trac.wordpress.org/browser/tags/3.1/wp-includes/pomo/streams.php#L86

you will see that it is a simple str_split(). How about if the $string argument is passed by reference ? The problem as it is explained to me is that right now the $string argument is passed by value, e.g. it is copied, so if this is a large string, it is going to take double space when it is used as an argument; instead if it is used as an argument passed by reference it will not take any extra space at all.

What do you think, would this help POMO_Reader::str_split() work with large strings ?

Change History (5)

  • Summary changed from pomo/streams.php suggestion ? to pomo/streams.php str_split() suggestion ?

comment:2 follow-up: ↓ 4   mrasnika2 years ago

It seems that this "optimization" is not going to help at all since all arguments are passed by reference UNTIL/UNLESS they are modified:

PHP already optimises it - variables are assigned using copy-on-write, and objects are passed by reference

http://stackoverflow.com/questions/496669/are-php-strings-immutable

  • Component changed from General to Performance

comment:4 in reply to: ↑ 2 ; follow-up: ↓ 5   hakre2 years ago

Replying to mrasnika:

It seems that this "optimization" is not going to help at all since all arguments are passed by reference UNTIL/UNLESS they are modified:

PHP already optimises it - variables are assigned using copy-on-write, and objects are passed by reference

http://stackoverflow.com/questions/496669/are-php-strings-immutable

And as it's copy on write, it's even counter-productive to pass by reference to built-in functions as this does even increase the memory usage.

If you need to be able to use more than 256MB of memory, you can use the working patch 13847.patch (Related: #13847) which replaces the hard-encoded memory limit value with a configure-able constant.

However if you're looking for memory optimizations for pomo, extending classes could be overwrite parent functions and access their resources more optimized.

A review of of the composition of the final objects are might reveal some structural benefit as well, AFAIK POMO tries to combine single and multibyte string operations with string- or file-io.

But that's structural and needs a refactoring plus testing if it really helps. So a lot of work.

Version 0, edited 2 years ago by hakre (next)

comment:5 in reply to: ↑ 4   SergeyBiryukov23 months ago

  • Keywords close added

Replying to hakre:

If you need to be able to use more than 256MB of memory, you can use the working patch 13847.patch (Related: #13847) which replaces the hard-encoded memory limit value with a configure-able constant.

According to the description, it's about 24 MB allocated, not 256 MB. I'd suggest closing as invalid, since the default memory limit in wp_initial_constants() is 32 MB.

Note: See TracTickets for help on using tickets.