Sane Excel file generation with Ruby on Rails
TL;DR: These are the 3 major steps we took to reduce our memory footprint (0.2Gb instead of 4Gb) and the time to generate the reports (2m instead of 15m): streamed the data directly to disk with xlsxtream; switched the memory allocator to jemalloc; and selected only what we needed, while avoiding ActiveRecord when pulling large amounts of data from the database
BetterDoc Product Development Blog