vapor / leaf-kit

🍃 An expressive, performant, and extensible templating language built for Swift.
https://docs.vapor.codes/4.0/leaf/getting-started
MIT License
49 stars 38 forks source link

Improved Rendering Performance #60

Closed tdotclare closed 4 years ago

tdotclare commented 4 years ago

This release substantially improves the rendering performance of Leaf on typical calls where the template is fully resolved and cached.

Performance Comparison

Linear

Branch Min Avg Max Avg Baseline Avg CPU Time CPU Baseline
1.0.0rc-1.13 4.27s 4.72s 5.14s 44.83% 1m 14s 40.72%
1.0.0rc-1.12 10.4s 10.52s 11.4s 100% 3m 1s 100%

Random

Branch Min Avg Max Avg Baseline Avg CPU Time CPU Baseline
1.0.0rc-1.13 4.43s 4.82s 5.17s 49.9% 1m 18s 45.3%
1.0.0rc-1.12 9s 9.66s 10.61s 100% 2m 51s 100%

NOTE this is purely a pipeline measurement - the templates used are lightweight and require near-zero time to serialize

tdotclare commented 4 years ago

Detailed Change Summary

This release substantially improves the typical rendering performance of Leaf on normal render calls where the AST storage adheres to SynchronousLeafCache

Internal Changes

SynchronousLeafCache adherents guarantee a non-future cache retrieval method if appropriate (eg, in-memory storage of the cache). This is currently an internal-only protocol that provides func retrieve(documentName: String) -> LeafAST? as a blocking retrieval method as an alternative to an EventLoopFuture<LeafAST?> return

In the typical use case where a call to LeafRenderer.render() references a template that is already present in the AST cache, is fully resolved, and is flat, this substantially improves render speed by skipping future handling.

Comparison to 1.0.0.rc-1.12 Performance

Linear

Branch Min Avg Max Avg Baseline Avg CPU Time CPU Baseline
1.0.0rc-1.12 10.4s 10.52s 11.4s 100% 3m 1s 100%
BlockingLeafCache 4.27s 4.72s 5.14s 44.83% 1m 14s 40.72%

Random

Branch Min Avg Max Avg Baseline Avg CPU Time CPU Baseline
1.0.0rc-1.12 9s 9.66s 10.61s 100% 2m 51s 100%
BlockingLeafCache 4.43s 4.82s 5.17s 49.9% 1m 18s 45.3%

NOTE this is purely a pipeline measurement - the templates themselves are lightweight and require next to no time to serialize

Other Notes

tanner0101 commented 4 years ago

These changes are now available in 1.0.0-rc.1.13