WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 8 months ago

Last modified 8 months ago

#16794 closed enhancement (invalid)

pomo/streams.php str_split() suggestion ?

Reported by: mrasnika Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.1
Component: Performance Keywords:
Focuses: 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 (7)

comment:1 mrasnika3 years ago

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

comment:2 follow-up: mrasnika3 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

comment:3 scribu3 years ago

  • Component changed from General to Performance

comment:4 in reply to: ↑ 2 ; follow-up: hakre3 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 might reveal some structural benefits 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.

Last edited 3 years ago by hakre (previous) (diff)

comment:5 in reply to: ↑ 4 SergeyBiryukov3 years 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.

comment:6 c3mdigital8 months ago

  • Resolution set to invalid
  • Status changed from new to closed

Closing based on Sergey's comments above.

comment:7 DrewAPicture8 months ago

  • Keywords close removed
  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.