Speeding Up willow.camp's post_test.rb by 99%

Cassia Scheffer · · 1 min read

I just asked Claude to speed up the slowest test file in willow.camp. post_test.rb was taking over 1 second to execute. For a tiny Ruby app, that’s a long time.

Here’s what Claude did. I was not expecting such a simple fix!

Test: test_should_detect_mermaid_diagrams_and_set_has_mermaid_diagrams_flag in test/models/post_test.rb:82

Issue: The test was using an unnecessarily large markdown string that required expensive processing through the Commonmarker library.

Optimization: Reduced the test markdown from a multi-section document to a minimal string that still tests the same functionality:

  • Before: Large heredoc with headers, multiple code blocks, and text content
  • After: Simple “mermaid\ngraph TD\n A --> B\n” string Performance Improvement:
  • Before: 1.31 seconds
  • After: 0.01 seconds
  • Improvement: 99%+ faster (130x speed improvement) The optimization maintains full test coverage while dramatically reducing execution time by eliminating unnecessary markdown processing overhead.

The original test was designed to evaluate a full-fledged Markdown document that was about 10 lines long. I didn’t need that in this case because I just needed to test that my custom mermaid code block worked.

Thanks Claude!