Reworking Memory Management in CRuby
Shopify sponsors and collaborates with academia to take Ruby to new heights. In this post, we give an overview of what we've built in collaboration with the Australian National University.
Shopify sponsors and collaborates with academia to take Ruby to new heights. In this post, we give an overview of what we've built in collaboration with the Australian National University.
We implemented a new feature to TypedData objects in Ruby, called embedded TypedData objects. TypedData objects are used across a wide variety of Ruby types, such as Time, Enumerator, and Method. This feature improves allocation speed and runtime performance, while decreasing memory usage. In this blog post, we'll look at what TypedData objects are under the hood, how embedded TypedData objects work, and the performance impacts of embedded TypedData objects.
Until recently, Ruby lacked a mechanism for detecting native-level memory leaks from within Ruby and native gems. This meant that it was hard to analyze Ruby applications that suffered from memory leaks, causing them to consume increasing amounts of memory until the system runs out and terminates the application. In this blog post, we'll be looking at the RUBY_FREE_AT_EXIT feature, which allows memory leak checkers to find memory leaks in Ruby and in native gems.
Ruby's garbage collector is designed to be adaptable, scaling from short Ruby scripts to running apps that serve millions of requests per second. While it's designed to be adaptable, it may not work optimally for every use case. For this reason, Ruby's garbage collector supports many parameters that can be used to tune it. However, the use of these parameters requires knowledge into how the garbage collector works on the inside. Learn how the Autotuner gem can analyze your app's traffic and provide suggestions for tuning the garbage collector.
Tips and tricks for the inevitable day: when the C extension crashes.
At Shopify, we are constantly improving the performance of Ruby for everyone. Based on analysis of and experiments on one of our largest and highest traffic apps, we found two improvements in Ruby's garbage collector that significantly improved our garbage collector performance, which in turn reduced our response times by 8%.
Overview of how Ruby's garbage collector works.
We've open sourced the definitions to build the Ruby we use at Shopify in development, testing, and production.
Tools and methodologies to benchmark Ruby code.
Learn more about Variable Width Allocation, a new feature in Ruby 3.2 that improves performance by optimizing Ruby's memory layout.
Practice your C extensions skills with a small project.
Sometimes things don't go as expected and need to raise or rescue from errors.
Are you a maintainer of a Ruby native extension gem? rb_gc_force_recycle will be deprecated in Ruby 3.1. Read to find how it affects you.
Let's look at this special type of object that only exists in C extensions called TypedData objects.
Let's look at the internals of ruby_memcheck, a tool to find memory leaks in native gems.
Finding and fixing a memory leak in Ruby strings.
Defining classes and modules and creating instances of classes.
Reading and writing instance variables, class variables, global variables, and constants through the Ruby C API.
The primitive data types in the Ruby C API and how to use them.
Calling Ruby methods in C extensions.
Defining Ruby methods in C extensions.
Let's look at how to set up and build your first Ruby C extension!
A series on writing your very first Ruby C extension, from scratch!
What's the midpoint between 0 and infinity in Ruby? It's 1.5 for some reason. What's the reason you might ask? Read on to find out.
A story about memory corruption inside Ruby when you create strings the wrong way.
There are many different ways to create Ruby strings in C, and choosing the wrong one can have catastrophic effects. So which one do you choose?
Overview of how Ruby's garbage collector works in Ruby 3.0.
Tips on development, tools, and debugging in MRI Ruby.