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

Performance improvement in PropelObjectCollection #999

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

romantymoshyk
Copy link

Reduced count of excess conditions in loop

Reduced count of excess conditions in loop
@staabm
Copy link
Member

staabm commented Aug 11, 2015

I dont believe this has a measurable impact. Before the value also was only evaluated once

@romantymoshyk
Copy link
Author

@staabm, you are right, value evaluated once, but condition tested on each round of foreach. For example in collection with 20 000 items in worst case it will check 20 000 times. Let take our collection of 20 000 objects, each model has methods that let us to add or remove object in collection. On each call of add object to collection method, getIdenticalObject called 3 times(first by method "contains", than by method "search", than one more time from "contains" in method doAdd...), on call "remove" it called 2 times. So to add or remove item in collection with 20 000 items we need ~ 60 000 times validate condition: "null === $objectHashCode". You still think that this has no measurable impact?

@staabm
Copy link
Member

staabm commented Aug 11, 2015

Ok, so it seems you measured the diff already? Would you post the results of your benchmark?

@romantymoshyk
Copy link
Author

Next code was used to measure performance of improvement:

        $author = new Author();
        for ($b = 1; $b <= 200; $b++) {
            $book = new Book();
            $author->addBook($book);
        }
        $author->save();

        foreach (iterator_to_array($author->getBooks()) as $book) {
            $author->removeBook($book);
        }

        $author->save();

Test code was runned from cli.
Environment: Win7, MySQL 5.6, PHP 5.5(OpCache was disabled)
To measure performance used xDebug profiler.
For test above, performance improvement:
117 ms or 15.4% faster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants