[wp-trac] [WordPress Trac] #41305: Add lazily evaluated translations
WordPress Trac
noreply at wordpress.org
Thu Oct 4 05:17:30 UTC 2018
#41305: Add lazily evaluated translations
-------------------------------------------------+-------------------------
Reporter: schlessera | Owner: jnylen0
Type: enhancement | Status: assigned
Priority: normal | Milestone: 5.0
Component: I18N | Version: 4.8
Severity: normal | Resolution:
Keywords: has-patch early dev-feedback needs- | Focuses: rest-api,
testing | performance
-------------------------------------------------+-------------------------
Comment (by TimothyBlynJacobs):
I think the way the lazy property is computed could be changed. My
understanding is that using an uninitialized property forces PHP to
allocate a hash table for the object which takes more memory than having
just a declared list of properties.
When I benched the difference there was a considerable difference in
memory.
Uninitialized Property
- Time: 10.40907907486
- Memory: 550,057,104
Declared Property
- Time: 9.9305930137634
- Memory: 174,057,104
{{{#!php
<?php
$s_time = microtime( true );
$s_mem = memory_get_usage();
for ( $i = 0; $i < 1000000; $i ++ ) {
$$i = __( 'My String' );
(string) $$i;
}
$d_time = microtime( true ) - $s_time;
$d_mem = memory_get_usage() - $s_mem;
echo $d_time . PHP_EOL;
echo $d_mem . PHP_EOL;
}}}
I didn't notice any consistent difference between the two methods when
repeatably accessing the same lazy string.
( I'm not super familiar with benchmarking, but I think this is rightish.
)
https://gist.github.com/nikic/5015323
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41305#comment:30>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list