parsica-php / parsica

Parsica - PHP Parser Combinators - The easiest way to build robust parsers.
https://parsica-php.github.io/
MIT License
405 stars 18 forks source link

remove unnecessary indirection via guardEndOfStream() which gains ~4% performance #31

Closed staabm closed 3 years ago

staabm commented 3 years ago

this function overhead call on the hot path is expensive (in take1)

grafik

getting rid of the fn call therefore translates into a small perf boost

grafik

turanct commented 3 years ago

Hey!

Thanks for this contribution!

I've just tried to verify the 4% performance improvement using the phpbench benchmarks (available in this repository), and I don't really see the 4% improvement on my machine:

phpbench benchmark before the change

before-inline

phpbench benchmark after the change

after-inline

As you can see above, the best run is about ±10 microseconds faster with the change than without the change, however, the worst run is about ±300 microseconds slower than before the change.

Would you have the time/resources to do some more blackfire tests on this? e.g. doing the same parsing routine 20 times to get better averages?

thanks a lot!

staabm commented 3 years ago

agree, the perf improvement is not visible with phpbench. with blackfire it works though ¯_(ツ)_/¯

just verified on a newer php 7.4.16.. blackfire still agress the fn-call deleted with this PR shaves off 4-5%

turanct commented 3 years ago

Cherry-picked to main, thanks!