stencilproject / Stencil

Stencil is a simple and powerful template language for Swift.
https://stencil.fuller.li
BSD 2-Clause "Simplified" License
2.34k stars 224 forks source link

Caching loaded template lines to improve performance #345

Open pavel-trafimuk opened 10 months ago

pavel-trafimuk commented 10 months ago

Currently, Stencil load and parse template file for each new output file generation, this improve help to reduce repetitive logic and significantly improve performance (on 30-50%)

art-divin commented 9 months ago

cc @djbe

tothambrus11 commented 3 months ago

Hello, can somebody review this PR? This change seems to be very useful for our project at Hylo, where we generate thousands of pages for the documentation of the standard library using Stencil.

To my understanding, this would be a breaking change, as the caches require the generator functions to be mutating. In swift there might be a way to opt out of the strict value semantics and make the cache a mutable field that is not part of the object's value, something like the mutable keyword for struct members in C++ that allows the field to be mutated from a const function, thus allowing the introduction of caches with const API.