Hero – A handy, fast and powerful Go template engine
github.com
github.com
Disclaimer: I wrote a template engine (https://github.com/eknkc/amber) to make this easier (and I like that Jade syntax)
For example, let's say I want to show a usage stat, I'd pass something like { usage: 100, limit: 1000 } to the template engine. Let's say I want to add a percentage. I believe the calculation should be on the presentation layer. That's how I decide to present this particular data.
Go templates lack that functionality for no good reason. And if I'm gonna calculate that on the backend, why exactly am I using a template engine? I'd concatenate strings.
You will quickly find if you use this that it's in fact worse: go templates have LISP syntax. A set of atoms, specified in reverse Polish notation, doing function application to all but the first atom.
http://www.more-magic.net/posts/structurally-fixing-injectio...
What I know, most web apps need template parsing only at the beginning. Once initial startup is done, delivery of content is mostly constant.
For low traffic efficacy doesn't matter, for high traffic you should always cache the templates.
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-plug...
The problem with Golang, most developers look for performance instead of the features. People who use python or ruby look for better features and ease of development. So, Golang engineers develop applications and libraries which doesn't help anyone.
I write Go professionally now and it's just not a productive language. The concepts are there, but the execution was frankly quite lazy and inconsistent.
Never panic in an external API, but closing closed channels and random number functions panic in the same way Java throws checked exceptions.
Generics aren't important, except for slices, maps, and channels which are generic.
Really minor things like this add up
Google will probably fix these things with time though, or so I hope - at the moment go seems like a conflicted language.
It's unfortunate the post title was "fastest go template engine" since that draws away from how different the API is from the standard lib (think ERB/EJS v Mustache).
While I'm personally in the "logicless" camp, I know a lot of people who'd appreciate this. Even I would when building something quick and dirty.
Sorry, OP.
Nice work on your plugin and impressive benchmark statistics!
I think its more important, to choose a good template language thats easy, and doesnt mix code with template content.
So while the raw version is a bit too easy for my tastes (and the first to be listed) the escaped version is still easier/shorter than raw.
That's more than enough to raise my eyebrow.
All the usual bad stuff that comes with dependencies: will it be maintained? Will it have breaking changes? Will it leftpad?
And everyone knows the standard library template format, all the editors support it, if another coder joins the team they'll know it.
Meh, maybe I'm just not the target market for this...
I agree it's not worth the focus on fast, they should be focussed on improving the API for the stdlib templates (for example loading templates is not obvious, what I'd like to do is point it at a directory and load all templates under that dir, being able to set layouts and partials would be nice etc). Speed is not a big problem with the existing templating.
All things considered, it absolutely is noise. Unless the only thing your application does is serving templates. Even then, the entire response should be cached, both on the server and the client at first place.
Time: ~0.04ms
Memory usage: 2Kb
There is no context here and just a link to another benchmark which most aren't going to bother to read. If your selling point is that you're the fastest, you need to tell people why that's important, and what exactly is faster. These graphs give zero details on the work done, and the timings/memory usage suggest trivial work is done in the benchmark, which means it's likely to be wrong. Is it measuring loading or evaluating or both at once? How many templates, what is in them? Are they properly evaluated with lots of keys in them? Do they test functions, methods, built-in functions?
If you're interested in speed, I'd suggest setting up your own real-world benchmark, with separate charts for parse time (typically done once, of little importance) and evaluation time for sets of templates which are 30-100 templates big and include lots of dynamic content and other templates. That's close to real world use and will tell you if your library is a lot faster, it might even give you far more impressive numbers (reduced render time of typical templates from 100ms to 10ms for example).
Personally, like the parent, fastest is about 10th on my priorities list as long as speed is adequate (and 0.04ms per template is adequate), below: Correctness, Contextual escaping (very handy in stdlib, not supported?), Ease of Use, Partials, Layouts, Syntax, Docs, Adding another dependency, etc.
As a third party dependency for a core feature which would require me to impose your library on everyone who uses my library/app, your argument has to be very strong and there have to be multiple reasons to adopt the library and strong guarantees about future development/support. Speed is not enough, even if it was an order of magnitude better on significantly slower results (say 100ms -> 10ms), it would be just one bullet point and far down the list.
I hope this is helpful.
:P
Doesn't https://golang.org/pkg/html/template/#ParseGlob do exactly that?
I'd add whatever functionality you need to html/template in your own code rather than import a dependency.
How exactly are designers supposed to easily update? Why reinvent the wheel when far more matured templating engines exist?
As the web moves to the front end, this seems like a step backwards
Not in any way that counts.
Many web sites are perfectly fine with pure HTML/CSS.
The web isn't really "moving front end". I hate these fulljavascript websites that serves you articles, there is no need to use Javascript for that. Furthermore, isn't server-side rendering a thing even for "front-end frameworks"? server-side templates are still relevant. What is not is abusing Javascript everywhere even when it doesn't make sense.