Skip to content

Instantly share code, notes, and snippets.

@pboling
Last active February 11, 2024 16:33
Show Gist options
  • Save pboling/af8a0c9a095820ef8434 to your computer and use it in GitHub Desktop.
Save pboling/af8a0c9a095820ef8434 to your computer and use it in GitHub Desktop.
Slim vs Haml

Analysis of Slim vs. Haml Project Health

  • Static data as of April 13, 2015, some updates as of October 1, 2015
# Metric Haml Slim Winner
1 Issues Open Issues Open Issues Slim
2 Stars Stars Open Issues Slim
3 Quality Code Climate technical debt Code Climate maintainability -- Haml
4 Test Coverage Code Climate coverage -- Haml
5 Documentation Inline docs Inline docs Slim
6 Watchers 95 112 Slim
7 Forks 440 306 Haml
8 Pull Requests 11 1 Slim
9 Activity 1 commmit / Month 6 commits / Month Slim
10 Community 1 author / Month 4 authors / Month Slim
11 Raw HTML Compat No Yes Slim
12 Rails Streaming Compat No, and issue was closed in 2020 Yes Slim
13 Speed* 1.09x slower than ERB 1.12x slower than ERB -

*References

Rails Streaming Compatibility

The Haml issue has open since Sep 23, 2011, was bumped from 4.0 release, to 5.0 release, now to 6.0 release, with no end in sight, and people openly quesitoning if it is even possible. Haml has a notoriously difficult codebase.

Speed

Conventional wisdom was that Haml is slow, Slim is fast. However haml was rewritten to use hamlit based on a better parser and compiler optimizations (Ripper and Temple). Now haml is as fast as, or faster than slim. They are now roughly equivalent in speed, meaning speed is no longer a deciding factor between them.

@pboling
Copy link
Author

pboling commented Feb 15, 2023

In 2022 v6 of Haml was refreshed using the internals of Hamlit, and announced that it was finally faster than slim. Slim in turn was jolted back to life, releasing v5, and in 2023 slim may once again be faster.

slim-template/benchmarks#4

@pboling
Copy link
Author

pboling commented Feb 11, 2024

In February 2024 the various libraries tested in this benchmark are nearly identical in a basic performance test. Of course, YMMV depending on which features you use, and how much.

Test was run on a 16GB 13" M2 MacBook Pro running MacOS Sonoma 14.3.1.

❯ bundle install
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Fetching temple 0.10.3
Installing temple 0.10.3
Fetching slim 5.2.1
Fetching haml 6.3.0
Installing slim 5.2.1
Installing haml 6.3.0
Bundle complete! 6 Gemfile dependencies, 8 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
❯ ./run-benchmarks.rb
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
Warming up --------------------------------------
           erb 4.0.2    61.264k i/100ms
        erubi 1.12.0    64.087k i/100ms
   temple erb 0.10.3    58.292k i/100ms
          haml 6.3.0    60.975k i/100ms
          slim 5.2.1    60.300k i/100ms
Calculating -------------------------------------
           erb 4.0.2    656.704k (± 2.4%) i/s -      3.308M in   5.040677s
        erubi 1.12.0    670.228k (± 0.9%) i/s -      3.397M in   5.068270s
   temple erb 0.10.3    581.279k (± 1.0%) i/s -      2.915M in   5.014608s
          haml 6.3.0    612.146k (± 0.4%) i/s -      3.110M in   5.080135s
          slim 5.2.1    596.732k (± 6.4%) i/s -      3.015M in   5.088974s

Comparison:
        erubi 1.12.0:   670227.5 i/s
           erb 4.0.2:   656703.7 i/s - same-ish: difference falls within error
          haml 6.3.0:   612145.8 i/s - 1.09x  slower
          slim 5.2.1:   596731.6 i/s - 1.12x  slower
   temple erb 0.10.3:   581278.6 i/s - 1.15x  slower

./run-benchmarks.rb  35.35s user 0.35s system 97% cpu 36.554 total

Performance is no longer the reason to choose Slim!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment