3 ms·
Ideally, a template should be compiled into native code.
by junke 10y ago
Ideally, a template should be compiled into native code.
- masklinn 10y agoNot necessarily. 1. that requires parsing the template at compile-time (making it non-overridable at runtime) or the ability to generate executable code at runtime which break in NX-mandatory environment (e.g. appstore applications) 2. the runtime version may be much faster than the compile-time one, e.g. the rust Regex crate has both a runtime Regex structure and a regex! compiler plugin, the latter is currently significantly slower at runtime: https://github.com/rust-lang/regex#usage-regex-compiler-plugin https://github.com/rust-lang/regex#usage-regex-compiler-plug...
- junke 10y agoYes, "compile/load/execute" can take longer than simply "eval". You have to consider amortized costs: how often do you need to recompile your template (or your regex)? Likewise, are you really going to override the template at runtime or is the variable part of the template already compiled as branches in the resulting code? Whatever needs to be dynamic can be dynamic while compiling as much as possible ahead of time.
- Zoadian 10y agoThere is a web framework (vibed.org) written in the D programming language that does compile templates to native code.
- micmus 10y agoElixir's EEx templating engine compiles templates into plain elixir functions, which makes the templates really fast.