Which is better for performance? Using a macro for output in a for loop or calling an include using the 'with' params to pass data? Both are loading a file. But is stacking up a bunch of code in a macro file faster than using an small include file?

{% for item in entries %}
    {% include "/components/_item" with { item: item } %}
{% endfor %}


{% for item in entries %}
    {{ helpers.item(item) }}
{% endfor %}

If I had to guess, I'd say a macro would be faster because it's accessing the file system less. In any case, unless you're dealing with hundreds of thousands of calls, I'd also guess that's the difference is going to be negligible for most use cases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.