Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge duplicate array loops #208

Merged
merged 1 commit into from
Feb 14, 2017
Merged

Merge duplicate array loops #208

merged 1 commit into from
Feb 14, 2017

Conversation

thiemowmde
Copy link
Contributor

@thiemowmde thiemowmde commented Feb 7, 2017

This patch does have two effects:

  • It merges duplicate loops that looped the exact same arrays twice.
  • This allows to avoid a few duplicate condition checks, e.g. duplicate is_string.

This is a direct follow up for #205.

Bug: T157959

@thiemowmde
Copy link
Contributor Author

@mariushoch @JeroenDeDauw I suggest to merge at least this (and possibly #207) before tagging the new release (which is already prepared via #209).

@thiemowmde
Copy link
Contributor Author

Benchmarked locally. Performance gain is a bit more than 3%.

@JeroenDeDauw
Copy link
Contributor

3% when just calling the deserialization code? What about in any real world use case where the data needs to be read from somewhere? I imagine it is no longer significant then

@thiemowmde
Copy link
Contributor Author

Even if it's only 1% in a real world scenario, 1% equals 20 minutes, according to https://phabricator.wikimedia.org/T157013#2993060. Under these circumstances I don't think it's worth arguing what the value of duplicate code is.

@thiemowmde thiemowmde added this to the 2.3.0 milestone Feb 13, 2017
@thiemowmde thiemowmde mentioned this pull request Feb 13, 2017
@@ -52,6 +54,10 @@ private function getDeserialized( array $serialization ) {

foreach ( $serialization as $key => $statementArray ) {
if ( is_string( $key ) ) {
if ( !is_array( $statementArray ) ) {
throw new DeserializationException( 'The statements per property should be an array' );
Copy link

Choose a reason for hiding this comment

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

Would be nice to mention key in the message

@@ -52,6 +54,10 @@ private function getDeserialized( array $serialization ) {

foreach ( $serialization as $key => $snakArray ) {
if ( is_string( $key ) ) {
if ( !is_array( $snakArray ) ) {
throw new DeserializationException( 'The snaks per property should be an array' );
Copy link

Choose a reason for hiding this comment

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

Would be nice to mention key here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both cases are old exception messages, and I did not wanted to change them, but I can.

@JeroenDeDauw
Copy link
Contributor

Well is it even 1%? If it's 3% just when executing the PHP code I expect it to be way less than 1% when holding i/o into account.

@manicki
Copy link
Member

manicki commented Feb 14, 2017

+1
I am not convinced by the impact of this but I not opposing.

@manicki manicki merged commit 7d7b0ce into master Feb 14, 2017
@manicki manicki deleted the arrayLoops branch February 14, 2017 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants