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

Succeed: use private properties lookup instead of calling getters - gains ~6% #35

Closed staabm closed 3 years ago

staabm commented 3 years ago

its technically allowed to do property lookups of private properties on objects of the same class, within said class. this reduces a unneccessary method call on a very hot path.

grafik

before

+-----------+----------------------+-----+------+-----+------------+--------------+--------------+--------------+--------------+-------------+--------+-----------+
| benchmark | subject              | set | revs | its | mem_peak   | best         | mean         | mode         | worst        | stdev       | rstdev | diff      |
+-----------+----------------------+-----+------+-----+------------+--------------+--------------+--------------+--------------+-------------+--------+-----------+
| JSONBench | bench_json_encode    | 0   | 5    | 3   | 1,661,896b | 13.200μs     | 13.267μs     | 13.212μs     | 13.400μs     | 0.094μs     | 0.71%  | 1.00x     |
| JSONBench | bench_Parsica_JSON   | 0   | 5    | 3   | 2,183,336b | 21,485.600μs | 23,175.600μs | 22,103.476μs | 25,870.800μs | 1,926.191μs | 8.31%  | 1,746.90x |
| JSONBench | bench_basemax_jpophp | 0   | 5    | 3   | 1,868,392b | 1,399.200μs  | 1,546.600μs  | 1,541.986μs  | 1,695.800μs  | 121.093μs   | 7.83%  | 116.58x   |
+-----------+----------------------+-----+------+-----+------------+--------------+--------------+--------------+--------------+-------------+--------+-----------+

after

+-----------+----------------------+-----+------+-----+------------+--------------+--------------+--------------+--------------+-----------+--------+-----------+
| benchmark | subject              | set | revs | its | mem_peak   | best         | mean         | mode         | worst        | stdev     | rstdev | diff      |
+-----------+----------------------+-----+------+-----+------------+--------------+--------------+--------------+--------------+-----------+--------+-----------+
| JSONBench | bench_json_encode    | 0   | 5    | 3   | 1,661,896b | 13.200μs     | 13.400μs     | 13.400μs     | 13.600μs     | 0.163μs   | 1.22%  | 1.00x     |
| JSONBench | bench_Parsica_JSON   | 0   | 5    | 3   | 2,183,336b | 21,035.800μs | 21,383.533μs | 21,287.141μs | 21,778.200μs | 304.895μs | 1.43%  | 1,595.79x |
| JSONBench | bench_basemax_jpophp | 0   | 5    | 3   | 1,868,392b | 1,360.000μs  | 1,368.200μs  | 1,361.492μs  | 1,384.600μs  | 11.597μs  | 0.85%  | 102.10x   |
+-----------+----------------------+-----+------+-----+------------+--------------+--------------+--------------+--------------+-----------+--------+-----------+
turanct commented 3 years ago

Cherry-picked the commit with the change to main. thanks for this PR! 🙇