BCrypt Hashing in Phoenix Tests

Zachery Moneypenny
Adorable
Published in
2 min readAug 31, 2017

This article is one of many efforts to seed Google with common sense solutions to problems that a first time Elixir/Phoenix developer might thrash against.

I’d been puzzled by how slow our Phoenix application test suite was; I didn’t think we were doing anything particularly heavy, computation-wise.

Our slow-ass test suite

When I googled around the topic I also didn’t see anyone else complaining so I figured it had to be something we were doing wrong specifically that was introducing an enormous amount of overhead.

This morning I was looking at some related search results and found a real interesting Stack Overflow question related to a slow Phoenix test suite. I realized that our test suite invokes a lot of bcrypt hashing because a lot of our tests validate expectations around authentication and authorization of various endpoints.

I wasn’t sure what the order of magnitude of the effect would be by reducing the number of bcrypt hashing rounds in our test environment, but, well check out the results of the one-line config change:

Our fast-ass test suite

We went from 90 seconds to 2 seconds based on that one-line config change! This config information is right in the comeonin setup documentation, but if you missed it then it’s a game changer when you realize the effect on your test suite. Applying this config is an easy and instant win.

Zachery Moneypenny is a Principal Developer at adorable.io. Rubyist for a long time, with experience in Golang and Javascript as well but moving towards Elixir and loving it.

--

--

Zachery Moneypenny
Adorable

engineering manager at cars.com | opinions on tech interviewing | woodworking | song-and-dance man