---
title: "Benchmarking Rack Middleware and Improved Speed"
description: "ActionDispatch::Static, enabled by config.serve_static_assets = true, checks incoming Rails requests to decide whether to serve a disk file or pass the request onward. To measure the middleware in isolation, the author loads it directly, wraps it around a no-op Proc, and uses Rack::MockRequest with benchmark-ips to compare requests against the no-op baseline. The original middleware achieved 15,891.2 iterations per second, versus 28,660.9 for the no-op, while the modified version reached 24,490.9 iterations per second. That change made non-asset middleware requests roughly 54% faster, bringing the gap to the no-op case to about 10%, although asset requests became slightly slower and the difference was not measurable. Across the full Rails application stack, the reported overall speedup was approximately 2.6%."
---

# Benchmarking Rack Middleware and Improved Speed

[Heroku](https://yomu.fyi/company/heroku) · Richard Schneeman · Nov 3, 2014

**Type:** Benchmark

## Summary

ActionDispatch::Static, enabled by config.serve\_static\_assets = true, checks incoming Rails requests to decide whether to serve a disk file or pass the request onward. To measure the middleware in isolation, the author loads it directly, wraps it around a no-op Proc, and uses Rack::MockRequest with benchmark-ips to compare requests against the no-op baseline. The original middleware achieved 15,891.2 iterations per second, versus 28,660.9 for the no-op, while the modified version reached 24,490.9 iterations per second. That change made non-asset middleware requests roughly 54% faster, bringing the gap to the no-op case to about 10%, although asset requests became slightly slower and the difference was not measurable. Across the full Rails application stack, the reported overall speedup was approximately 2.6%.

## Context

ActionDispatch::Static checks every incoming request when Rails static asset serving is enabled, using a disk lookup to determine whether to serve a file or pass the request onward. The author needed a way to measure this individual Rack middleware rather than only the complete Rails application stack.

## Approach / What changed

The middleware was loaded directly and instantiated around a no-op Proc, then exercised through Rack::MockRequest. benchmark-ips compared middleware requests with requests against the no-op baseline, using five-second warmup and measurement periods; the middleware was then tested after optimizations intended to avoid disk access.

## Takeaways

- The benchmark compared ActionDispatch::Static with a no-op Rack endpoint, treating the no-op as the fastest practical baseline for middleware overhead.
- The modified middleware reached 24,490.9 iterations per second compared with 15,891.2 for the original when handling a request that did not request a file.
- Optimizing non-asset requests introduced more logic and made asset requests slightly slower, though the asset-request difference was not measurable in the reported tests.

**Tags:** [Performance](https://yomu.fyi/topic/performance), [Ruby on Rails](https://yomu.fyi/topic/ruby-on-rails)

- Source: [Heroku](https://www.heroku.com/blog/benchmarking-rack-middleware)
- Source URL: https://www.heroku.com/blog/benchmarking-rack-middleware
- Ingested by Yomu: 2026-09-09T14:23:42.372Z

[Read original post](https://www.heroku.com/blog/benchmarking-rack-middleware)
