How Crystal Performs Compared to Ruby — Filtering Module for Marketplace

Guillaume Voisin
2 min readNov 14, 2019

--

To put things in context, I and my partner are launching a marketplace for babysitters soon in Budapest, Hungary.

Current open-source marketplaces don’t fit our expectations. We need a marketplace that is both very fast and good looking. We also need the code to be flexible enough to add custom features quickly.

Hence I decided to build it from scratch. To have a great UX, I’ll rely on Vue.js and I’ll code the backend using Ruby on Rails.
The app will be a monolith where NGINX passes requests to either a Rails or Crystal server.
I chose Rails for fast-paced development and Crystal for performance (using Amber).

Building the filtering module — Crystal vs Ruby

I coded the filtering module both in Crystal and Ruby. I’d like to share with you how it impacts the performances and the user experience.

A quick look at the UI/UX

Search via a set of filters — Work in progress

Ruby version

Controller:

Model:

Crystal version

Controller:

Model:

How it performs

HTTP GET that returns 25 items

  • Ruby (Ruby on Rails): 21ms
  • Crystal (Amber): 9.7ms
25 results

HTTP GET that returns 100 items

  • Ruby (Ruby on Rails): 32ms
  • Crystal (Amber): 16ms
100 results

HTTP GET that returns 500 items

  • Ruby (Ruby on Rails): 114ms
    At this size of the query, we start to feel a bit of lag.
  • Crystal (Amber): 33.12ms
500 results

Summary

Comparison between Rails & Amber

Conclusion

In that context, Ruby on Rails gets slow above 400 items, but that’s not a big problem. We just have to chunk the result into sets of 50 items, load content when the user scrolls and that does the trick, we’re below 50ms.

Amber offers excellent performance, we can use the same strategy (add a LIMIT 50, paginate) and stay below 15ms for every query! That’s great! :)

I hope this quick comparison was useful to you and maybe gave you the will to try Crystal ;). Crystal can be very useful for long sidekiq jobs or HTTP queries that can’t be cached.

Thanks for reading!

By the way, I work as an independent contractor, feel free to contact me if you need to get a marketplace done.

--

--