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

Store temporary macro function result vars #920

Merged
merged 3 commits into from
Oct 5, 2022

Conversation

jasmith-hs
Copy link
Contributor

Currently if there is a macro function that cannot be fully evaluated and it's used in a situation where partial evaluation is not an option, the evaluation result will be discarded. For example:

{{ caller()|replace('\n', ' ' ) }}

If calling caller() had some deferred tokens, we would have to discard the result because we couldn't run the filter on the non-fully evaluated macro result. This meant that the macro function would need to get run again later, which was expensive and could cause some issues if the function was not idempotent.
Instead, if the result is stored, we can convert it to:

{% set __macro_caller_temp_variable_0 %}
...
{% endset %}
{{ __macro_caller_temp_variable_0|replace('\n', ' ') }}

This reduces the duplication of work needed, leading to a faster final render and a faster initial render in many circumstances.

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.

1 participant