Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DomCrawler] minor performance improvement #26423

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

Closed
wants to merge 2 commits into from

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented Mar 6, 2018

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

@ostrolucky
Copy link
Contributor

Changing weak to strict comparison in public method is potentially breaking change and should not be done in patch release

@dunglas
Copy link
Member Author

dunglas commented Mar 7, 2018

@ostrolucky not here, because the test is in a foreach (https://3v4l.org/ElUI2) and the parameter is documented as int in the PHPDoc.

@ostrolucky
Copy link
Contributor

I know $i is guaranteed to be integer, but not $position. Yes, blame can be put on user if they didn't make sure argument is integer. That's why I consider this change ok to do in minor release without migration path. For patch release IMHO it is too risky to change how code processes arguments with no good reason, regardless if it's documented in phpdoc. Few years back double equals operator was more common and applications could count with the fact that int in API meant more like number.

Also, it seems this provides no performance boost if data types compared are same https://stackoverflow.com/a/14520998/524965

@javiereguiluz
Copy link
Member

I agree with @ostrolucky about the strict comparison: this kind of changes is too risky in a patch version. Better do that in master. Thanks!

@jakzal
Copy link
Contributor

jakzal commented Mar 8, 2018

How big is the performance gain?

@dunglas
Copy link
Member Author

dunglas commented Mar 10, 2018

$position is documented as int in the Docblock, we don't garantee BC on unsupported types, but I'll target master as it's not a bug fix.

@jakzal I've not benchmarked it, but on large documents it should be important (calling a method in a loop for nothing always come with a big cost).

@dunglas dunglas changed the base branch from 2.7 to master March 10, 2018 11:06
@fabpot
Copy link
Member

fabpot commented Mar 10, 2018

Looks like there are some unrelated commits here.

@dunglas dunglas force-pushed the dom-crawler-optim branch from 8d80108 to d615fc9 Compare March 11, 2018 08:48
@dunglas dunglas changed the title [DomCrawler] Invert a test to improve perf + use strict comparison [DomCrawler] minor performance improvement Mar 11, 2018
@dunglas
Copy link
Member Author

dunglas commented Mar 11, 2018

@fabpot Fixed.

@ostrolucky @javiereguiluz the comparison has already been removed in master, problem fixed!

do {
if ($node !== $this->getNode(0) && 1 === $node->nodeType) {
if ($node !== $currentNode && 1 === $node->nodeType) {
Copy link
Member

Choose a reason for hiding this comment

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

Minor thing: why not use XML_ELEMENT_NODE === $node->nodeType instead of 1 === $node->nodeType ? It's more readable to use http://php.net/manual/en/dom.constants.php and we already do that in other parts of this same class.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, can I do it in the same PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@nicolas-grekas nicolas-grekas added this to the 4.1 milestone Mar 12, 2018
@nicolas-grekas
Copy link
Member

Thank you @dunglas.

nicolas-grekas added a commit that referenced this pull request Mar 14, 2018
This PR was squashed before being merged into the 4.1-dev branch (closes #26423).

Discussion
----------

[DomCrawler] minor performance improvement

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? |no <!-- don't forget to update UPGRADE-*.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | n/a   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | n/a

Commits
-------

eead301 [DomCrawler] minor performance improvement
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.

8 participants