Overengineering Ruby with Native Extensions
summary
A Rails CSV importer parses a million rows in ~7 seconds and consumes ~1.1 GB memory with plain Ruby; building a C native extension yields 9.4x faster runtime but still high memory and observability gaps, Rust extension using the CSV crate runs ~1.22s with ~850 MB, FFI runs ~3.2s with ~620 MB, and native code requires mkMF/make, libcsv or homebrew links and Perf to profile. Switching to streaming: 5s 300 MB fixes memory crashes without leaving Ruby.
AI-written summary · about
chapters (12)
- 0:00Introduction
- 1:30Native extensions in Ruby
- 4:23CSV parsing bottleneck
- 8:17Building and installing extensions
- 10:19Writing faster CSV extension
- 16:40Benchmarking performance
- 17:44Profiling native extensions
- 18:27C Rust and FFI comparison
- 20:54Trade-offs of extensions
- 21:38Fixing without extensions
- 22:42Key lessons
- 24:09Conclusion
related talks
40mTurbo Rails with Rust
29mImprove Performance Quick and Cheap: Optimize Memory and Upgrade to Ruby 2.1
24mRuby Performance Secrets and How to Uncover Them
30mBuilding Native Extensions. This Could Take A While...
47mRewriting a Ruby C Extension in Rust
50mUsing C to Tune Your Ruby (or Rails) Application
31mProcessing data: Ruby or SQL?
41mJRuby: Zero to Scale! 🔥
