Story Details

  • Fast Allocations in Ruby 3.5

    Posted: 2025-05-22 14:01:55

    Ruby 3.5 introduces a new object allocation mechanism called "layered compaction," which significantly speeds up object creation. Instead of relying solely on malloc for memory, Ruby now utilizes a multi-layered heap consisting of TLSF (Two-Level Segregated Fit) allocators within larger mmap'd regions. This approach reduces system calls, minimizes fragmentation, and improves cache locality, resulting in performance gains, especially in multi-threaded scenarios. The layered compaction mechanism manages these TLSF heaps, compacting them when necessary to reclaim fragmented memory and ensure efficient object allocation. This improvement translates to faster application performance and reduced memory usage.

    Summary of Comments ( 61 )
    https://news.ycombinator.com/item?id=44062160

    Hacker News users generally praised the Ruby 3.5 allocation improvements, with many noting the impressive performance gains demonstrated in the benchmarks. Some commenters pointed out that while the micro-benchmarks are promising, real-world application performance improvements would be the ultimate test. A few questioned the methodology of the benchmarks and suggested alternative scenarios to consider. There was also discussion about the tradeoffs of different memory allocation strategies and their impact on garbage collection. Several commenters expressed excitement about the future of Ruby performance and its potential to compete with other languages. One user highlighted the importance of these optimizations for Rails applications, given Rails' historical reputation for memory consumption.