Keats / tera

A template engine for Rust based on Jinja2/Django
http://keats.github.io/tera/
MIT License
3.36k stars 280 forks source link

parser: allocate vector with exact capacity #894

Closed lucab closed 5 months ago

lucab commented 5 months ago

This tweaks parse_content() logic in order to reduce the amount of vector growing, as the final vector capacity is already known beforehand.

lucab commented 5 months ago

For reference, parse_content() is indirectly recursive (through parse_block()) so the compounded effect of this is noticeable in memory patterns of consuming applications.

As an example, on a zola build run on the test_site this spot accounts for ~2% of all temporary allocations (where zola_patched is a local build of the next branch): tera

lucab commented 5 months ago

MSRV bump to fix CI is at https://github.com/Keats/tera/pull/895.

lucab commented 5 months ago

This has been rebased to latest master and CI is green, PR is now ready to be merged.

Keats commented 5 months ago

Thanks!