-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
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]): |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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]):
Given that the Inline class has quite some test coverage I think we don't need additional coverage. |
Thanks @alexpott. |
…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.  https://drupal.org/node/1851234 Commits ------- 10c898d Avoid unnecessary line indentation calculation. c65a647 Optimise Inline::evaluateScalar() for parsing strings.
switch (true) { | ||
case 0 === strpos($scalar, '!str'): | ||
return (string) substr($scalar, 5); | ||
case 0 === strpos($scalar, '! '): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 !
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed I have.
…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.
* 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
* 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.
The Drupal 8 installer does a lot of YAML parsing. With the patch attached it is significantly quicker.

https://drupal.org/node/1851234