Skip to content

Conversation

@marc-mabe
Copy link
Owner

@marc-mabe marc-mabe commented Oct 26, 2017

... on checking for ambiguous enumerator values.

This will speed up first enumeration call with a factor of ~3.

The BC break is because of it throws an AssertionError if zend.assertions = 1 or throws nothing.

@marc-mabe marc-mabe added this to the 3.0.0 milestone Oct 26, 2017
@marc-mabe marc-mabe force-pushed the opt_Enum_detectConstnats branch 4 times, most recently from 38dd474 to ff749d4 Compare October 26, 2017 20:21
src/Enum.php Outdated
}
}

return empty($ambiguous);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not throw an exception here like before? I am kind of against using assertions.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also see not why this should be so much faster.

@marc-mabe marc-mabe force-pushed the opt_Enum_detectConstnats branch 5 times, most recently from 549746b to 87a4b77 Compare October 26, 2017 21:05
@marc-mabe
Copy link
Owner Author

@prolic

Assertions should be enabled in development move only and is designed for cases that should be evaluate to true ever. So if an assertion fails it notifies a programming error. Such errors must be detected on development and assertions are not needed to execute on production.

Please run the following benchmark with 9019505 applied before

php -d 'zend.assertions=1' ./vendor/bin/phpbench run --context="master" --filter=benchGetConstants --report=aggregate

+-----------+-------------------+--------+--------+------+-----+----------+----------+----------+----------+----------+---------+--------+-------+
| benchmark | subject           | groups | params | revs | its | mem_peak | best     | mean     | mode     | worst    | stdev   | rstdev | diff  |
+-----------+-------------------+--------+--------+------+-----+----------+----------+----------+----------+----------+---------+--------+-------+
| EnumBench | benchGetConstants |        | []     | 2500 | 25  | 960,816b | 50.800μs | 51.402μs | 51.015μs | 52.034μs | 0.430μs | 0.84%  | 0.00% |
+-----------+-------------------+--------+--------+------+-----+----------+----------+----------+----------+----------+---------+--------+-------+

then comment out the code for assertions.

+-----------+-------------------+--------+--------+------+-----+----------+----------+----------+----------+----------+---------+--------+-------+
| benchmark | subject           | groups | params | revs | its | mem_peak | best     | mean     | mode     | worst    | stdev   | rstdev | diff  |
+-----------+-------------------+--------+--------+------+-----+----------+----------+----------+----------+----------+---------+--------+-------+
| EnumBench | benchGetConstants |        | []     | 2500 | 25  | 958,928b | 13.757μs | 13.975μs | 13.971μs | 14.154μs | 0.097μs | 0.69%  | 0.00% |
+-----------+-------------------+--------+--------+------+-----+----------+----------+----------+----------+----------+---------+--------+-------+

@marc-mabe marc-mabe changed the title [WIP] Optimize Enum::detectConstants() by using assertion Optimize Enum::detectConstants() by using assertion Oct 26, 2017
Copy link
Collaborator

@prolic prolic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understand, great idea!

@marc-mabe marc-mabe force-pushed the opt_Enum_detectConstnats branch from 87a4b77 to 42f65d0 Compare October 27, 2017 17:21
@marc-mabe marc-mabe force-pushed the opt_Enum_detectConstnats branch from 42f65d0 to 978ee3a Compare October 27, 2017 17:32
@marc-mabe marc-mabe merged commit df05fed into master Oct 27, 2017
@marc-mabe marc-mabe deleted the opt_Enum_detectConstnats branch October 31, 2017 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants