Skip to content

[Yaml] Optimise Inline::evaluateScalar() for parsing strings. #10312

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

alexpott
Copy link
Contributor

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

The Drupal 8 installer does a lot of YAML parsing. With the patch attached it is significantly quicker.
image

https://drupal.org/node/1851234

@alexpott
Copy link
Contributor Author

Found another optimisation. Happy to split this into a separate PR if you think it is worth it.

Again this has quite a big impact on the Drupal installer.
image

case preg_match(self::getTimestampRegex(), $scalar):
return strtotime($scalar);
// Optimise for returning strings.
case $scalar[0] === '+' || $scalar[0] === '-' || $scalar[0] === '.' || $scalar[0] === '!' || is_numeric($scalar[0]):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to not just use in_array(..., TRUE)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is slower. Not hugely - but in_array is more expensive
image

Copy link
Member

Choose a reason for hiding this comment

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

it's better to split the case statements:

case $scalar[0] === '+' :
case $scalar[0] === '-':
case $scalar[0] === '.':
case $scalar[0] === '!':
case is_numeric($scalar[0]):

@dawehner
Copy link
Contributor

Given that the Inline class has quite some test coverage I think we don't need additional coverage.

@fabpot
Copy link
Member

fabpot commented Feb 23, 2014

Thanks @alexpott.

fabpot added a commit that referenced this pull request Feb 23, 2014
…ings. (alexpott)

This PR was submitted for the 2.3-dev branch but it was merged into the 2.3 branch instead (closes #10312).

Discussion
----------

[Yaml] Optimise Inline::evaluateScalar() for parsing strings.

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

The Drupal 8 installer does a lot of YAML parsing. With the patch attached it is significantly quicker.
![image](https://f.cloud.github.com/assets/769634/2237906/630c3308-9bcf-11e3-8038-35cbbeedd7e6.png)

https://drupal.org/node/1851234

Commits
-------

10c898d Avoid unnecessary line indentation calculation.
c65a647 Optimise Inline::evaluateScalar() for parsing strings.
@fabpot fabpot closed this Feb 23, 2014
switch (true) {
case 0 === strpos($scalar, '!str'):
return (string) substr($scalar, 5);
case 0 === strpos($scalar, '! '):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use $scalar[0] === '!' here as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

The strpos() check would still be required for differentiating between !str and !, and all other cases, so that change would not present a perf improvement.

Copy link
Member

Choose a reason for hiding this comment

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

@Tobion have you missed the space after ! ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed I have.

sun added a commit to sun/symfony that referenced this pull request Feb 25, 2014
fabpot added a commit that referenced this pull request Feb 25, 2014
…line. (sun)

This PR was submitted for the 2.3-dev branch but it was merged into the 2.3 branch instead (closes #10323).

Discussion
----------

[Yaml] Fixed minor performance related issues in Yaml\Inline.

Follow-up to #10312

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Commits
-------

a36fef5 Follow-up to #10312: Fixed minor performance related issues in Yaml\Inline.
fabpot added a commit that referenced this pull request Feb 27, 2014
* 2.3:
  bumped Symfony version to 2.3.12
  updated VERSION for 2.3.11
  update CONTRIBUTORS for 2.3.11
  updated CHANGELOG for 2.3.11
  Follow-up to #10312: Fixed minor performance related issues in Yaml\Inline.

Conflicts:
	src/Symfony/Component/HttpKernel/Kernel.php
fabpot added a commit that referenced this pull request Mar 3, 2014
* 2.4:
  [Form][2.3] Fixes empty file-inputs getting treated as extra field.
  changed some PHPUnit assertions to more specific ones
  fixed Kernel::stripComments() normalizing new-lines
  added a BC comment
  Update FileLoader to fix issue #10339
  bumped Symfony version to 2.3.12
  updated VERSION for 2.3.11
  update CONTRIBUTORS for 2.3.11
  updated CHANGELOG for 2.3.11
  Throw exception when unable to normalize embedded object
  Fixed evaluation of short circuit operators
  Follow-up to #10312: Fixed minor performance related issues in Yaml\Inline.
  [2.4][HttpKernel] Fix issue #10209 When the profiler has `only_exception` option activated and a subrequest throw an exception, the parent profile cannot be found.
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.

7 participants