On Sat, Jul 31, 2021 at 6:10 AM Tim Starling <[email protected]> wrote:
>
> For performance sensitive tight loops, such as parsing and HTML construction,
> to get the best performance it's necessary to think about what PHP is doing
> on an opcode by opcode basis.
...
> I am proposing
>
> if ( $x == 1 ) {
> action1();
> goto not_2; // avoid unnecessary comparison $x == 2
> } else {
> action_not_1();
> }
> if ( $x == 2 ) {
> action2();
> } else {
> not_2:
> action_not_2();
> }
...
> I am requesting that goto be considered acceptable for micro-optimisation.
ha, what question. the single goto and its target are 5 lines apart,
even me php incompetent person can understand it.
you triggered me reading more about it though. the commit comment
states it takes 30% less instructions:
Measuring instruction count per iteration with perf stat, averaged over
10M iterations, PS1. Test case:
Html::openElement('a', [ 'class' => [ 'foo', 'bar' ] ] )
* Baseline: 11160.7265433
* in_array(): 10390.3837233
* dropDefaults() changes: 9674.1248824
* expandAttributes() misc: 9248.1947500
* implode/explode and space check: 8318.9800417
* Sanitizer inline: 8021.7371794
does this mean these changes bring 30% speed improvement? that is
incredible! how often is this part called to retrieve one article?
now i understand why legoktm is prepared to rewrite mediawiki in rust
(https://www.mediawiki.org/wiki/Template:User_Rust), and why proposals
exist to extend php with rust (https://github.com/rethinkphp/php-rs ,
https://docs.rs/solder/0.1.6/solder/ ). tempted i was to use legoktm's
template on my user page, when i finally saw that php is amazing with
regular expressions by including pcre c library:
https://benchmarksgame-team.pages.debian.net/benchmarksgame/performance/regexredux.html
.
rupert
_______________________________________________
Wikitech-l mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/