Cells-Hamlit: The Fastest View Engine Around.

The Hamlit gem is a reimplementation of the popular Haml markup language, which unfortunately is based on a quite old, convoluted codebase. Hamlit borrows the syntax, but rewrites the entire engine code leveraging the excellent Temple gem, which is a parser, compiler and optimizer for template languages and is also used in Slim.

Wow, that’s four template gems in one paragraph, but I’m pretty sure you’ve heard of all of them, except for maybe Hamlit.

Why Hamlit?

What makes Hamlit attractive for us is a very clean code base and speed.

Hamlit refrains from monkey-patching Rails helpers. Where the original Haml gem has quite a few of controversial Rails hacks, Hamlit has zero coupling to Rails. The capture support can be simplified using the Hamlit-block gem – instead of relying on different output buffers, capture always returns the captured content directly. This is brilliant for Cells.

Speaking of: If you want to use Hamlit in Cells, we provide you the Cells-hamlit gem. This was mainly possible because of Takashi Kokubun‘s excellent work and collaboration.

Need For Speed.

View rendering with Cells and Hamlit views is very fast. It’s actually the fastest combination at the time of writing this post.

ChartGo

For a simple benchmarking I used Benchmark-ips in the Gemgem-Sinatra application, a nice sample project that shows how to use Trailblazer and Cells in Sinatra. The benchmark file simply renders an entire page using Cells, as many times as possible in 20 seconds.

The cells composing the page use Hamlit, Slim and Haml templates in different branches. The result is always this page.

Screenshot_2016-01-23_14-24-51

This is all nothing special. However, as visible in my professional 3D chart, say Hamlit was 100%, Slim’s performance is 90%, whereas Haml can perform only 80% of what Hamlit can. In other words: Hamlit is the fastest and will make your views perform better.

Note that this benchmark is in combination with Cells. Cells are generally faster than ActionView. With the upcoming Cells 4.1 we will have performance boosts of around 5-10 as compared to the ActionView framework.

Haml 5

To come to Haml’s defense: this project has notably paved the way for all modern template formats. Its popularity “skyrocketed”, to say it in DHH’s words, very early, making it hard for the core team to aggressively refactor the code base. This might happen in Haml 5 and could bring Haml-The Originalā„¢ back into pole position.

You should go and try out Hamlit today. Use it with Cells for a major boost in speed and a better view architecture.


If you want to stay up-to-date with all Trailblazer gems like Cells, Roar and Reform, sign up for our newsletter. It will give you a monthly overview of new features, cool tricks and upcoming awesomeness.

Advertisement

One thought on “Cells-Hamlit: The Fastest View Engine Around.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s