It might be interesting to point out to discussions around use of goto in Linux Kernel:
https://koblents.com/Ches/Links/Month-Mar-2013/20-Using-Goto-in-Linux-Kernel-Code/
https://www.kernel.org/doc/html/v4.10/process/coding-style.html#centralized-exiting-of-functions

IIRC (from a presentation by Greg KH I watched but I can't find it now), in Linux, goto forward is fine to use everywhere but goto backwards is only used in the scheduler. And the scheduler is special (to put it mildly). So I think using goto backwards should be highly discouraged and maybe downright banned but forward should be okay.

HTH

On Sun, Aug 1, 2021 at 8:05 AM rupert THURNER <rupert.thurner@gmail.com> wrote:
On Sat, Jul 31, 2021 at 6:10 AM Tim Starling <tstarling@wikimedia.org> 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 -- wikitech-l@lists.wikimedia.org
To unsubscribe send an email to wikitech-l-leave@lists.wikimedia.org
https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/


--
Amir (he/him)