HTTP/2: Why It Doesn't Matter in Ruby HTTP Servers

2025-02-25

This post discusses the relevance of HTTP/2 support in Ruby HTTP servers like Puma. The author argues that while HTTP/2's main advantage – multiplexing for faster page load times – is significant over the internet, it offers little benefit on a LAN. Low latency and long-lived connections within a LAN minimize the impact of TCP slow start. Furthermore, HTTP/2's server push feature proved detrimental and has been superseded by the more elegant 103 Early Hints. The author advocates leaving HTTP/2 handling to load balancers or reverse proxies, simplifying deployment and maintenance for the application server.

Read more
Development Network Performance

The Myth of the IO-Bound Rails App

2025-01-25

It's a common belief that Rails apps are inherently IO-bound, with the database being the primary performance bottleneck, making Ruby performance less critical. This post challenges that notion. While the database is indeed a scaling bottleneck, the author argues that this doesn't mean the application spends most of its time waiting for I/O. Analysis of YJIT performance improvements and common performance issues (like missing database indexes) suggests many Rails apps are actually CPU-bound. The post highlights confusion between CPU starvation and I/O wait, and emphasizes that choosing the right execution model (asynchronous, threaded, or process-based) depends on the app's I/O/CPU ratio. The author calls for attention to Ruby performance and points out opportunities for optimization within Rails itself.

Read more
Development

Optimizing Ruby's JSON: A Tale of Stack Allocation and Inlining

2025-01-02

This blog post, part four in a series on optimizing Ruby's JSON performance, details the author's journey in improving Ruby's JSON serialization speed. Through meticulous micro-benchmarking and profiling, the author explores stack allocation and inlining techniques. By shifting buffer allocation from the heap to the stack and strategically using inlining, significant performance gains are achieved. However, the article highlights the importance of balancing micro-benchmark improvements with real-world application performance, showcasing a case where optimization negatively impacted larger datasets.

Read more
Development

Optimizing Ruby's JSON: Part 1

2024-12-18

This blog post details how the author optimized Ruby's `json` gem to become one of the fastest JSON parsers and generators. Instead of complex techniques, simple optimizations were applied based on profiling, such as avoiding redundant checks, prioritizing cheaper conditions, reducing setup costs, and using lookup tables. These improvements apply to both C and Ruby code. The optimizations significantly boosted the `json` gem's performance, making it competitive with alternatives like `oj`, reducing the need for monkey patching, and addressing stability and compatibility issues associated with `oj`.

Read more