Skip to content

[TwigBundle] Add a check for choice's attributes emptiness before calling block('attributes') #19574

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

Merged
merged 2 commits into from
Aug 17, 2016

Conversation

johnatannvmd
Copy link
Contributor

@johnatannvmd johnatannvmd commented Aug 9, 2016

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
License MIT

Remove unnecessary block calling for choices without "choice_attr" option. This check gain the performance on a large datasets.

Previous Pull to master #19527

@@ -79,8 +79,7 @@
{{- block('choice_widget_options') -}}
</optgroup>
{%- else -%}
{% set attr = choice.attr %}
<option value="{{ choice.value }}" {{ block('attributes') }}{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ choice_translation_domain is same as(false) ? choice.label : choice.label|trans({}, choice_translation_domain) }}</option>
<option value="{{ choice.value }}" {% if choice.attr %}{% set attr = choice.attr %}{{ block('attributes') }}{% endif %}{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ choice_translation_domain is same as(false) ? choice.label : choice.label|trans({}, choice_translation_domain) }}</option>
Copy link
Member

Choose a reason for hiding this comment

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

The space before {% if should be moved after the if

@fabpot
Copy link
Member

fabpot commented Aug 16, 2016

Do you have any numbers to share about the perf gain?

@johnatannvmd
Copy link
Contributor Author

Twig Metrics:

Opt Render time Template calls Block calls
Before 256 ms 5 300
After 199 ms 5 50
Difference 57 ms

It is about 50% of the overall request time.

@fabpot
Copy link
Member

fabpot commented Aug 17, 2016

Thank you @johnatannvmd.

@fabpot fabpot merged commit bf6748d into symfony:2.7 Aug 17, 2016
fabpot added a commit that referenced this pull request Aug 17, 2016
…ss before calling block('attributes') (Evgeniy Tetenchuk, johnatannvmd)

This PR was merged into the 2.7 branch.

Discussion
----------

[TwigBundle] Add a check for choice's attributes emptiness before calling block('attributes')

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT

Remove unnecessary block calling for choices without "choice_attr" option. This check gain the performance on a large datasets.

Previous Pull to master #19527

Commits
-------

bf6748d Move space from the before 'if' to the after 'if'
d1cf4d1 [TwigBundle] Add a check for choice's attributes emptiness before calling block('attributes')
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.

3 participants