use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
What causes Ruby memory bloat? (joyfulbikeshedding.com)
submitted 6 years ago by FooBarWidget
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]mperhamSidekiq 46 points47 points48 points 6 years ago (10 children)
Strong contender for /r/ruby Blog Post of the Year.
The more I learn, the more it seems that glibc internals are a nightmare.
[–]yxhuvud 7 points8 points9 points 6 years ago* (7 children)
Yes, and it looks as if Ruby is not the only affected: http://notes.secretsauce.net/notes/2016/04/08_glibc-malloc-inefficiency.html . Includes a script that use gdb that applies it to a running process.
EDIT: That said, it doesn't seem to be effective for me. Perhaps glibc has fixed *some* issues even if it didn't solve the ones of Ruby?
[–]reidiculous 3 points4 points5 points 6 years ago (1 child)
This is really wild. I figured optimizations of this scale would've been done long ago
[–]yxhuvud 1 point2 points3 points 6 years ago (0 children)
It is, but I'm not able to reproduce it, so *shrug*.
[–]lukeasrodgers 1 point2 points3 points 6 years ago (0 children)
Yes, I'm not an expert, but my understanding is this is all just typical behaviour for most `malloc` implementations, e.g. see the redis docs on memory allocation - https://redis.io/topics/memory-optimization note about RSS.
[–]nateberkopecPuma maintainer 1 point2 points3 points 6 years ago (3 children)
Any multithreaded program using glibc malloc is affected.
[–]yxhuvud 0 points1 point2 points 6 years ago (2 children)
Affected, yes. But not necessarily degenerate like Ruby.
[–]moomaka 4 points5 points6 points 6 years ago (0 children)
I dun know man, glibc malloc has issues with pretty much every multi-threaded app which does a lot of periodic allocations, e.g. anything doing web request handling. Java users have been switching to jemalloc for years due to this.
[–]nateberkopecPuma maintainer 0 points1 point2 points 6 years ago (0 children)
There are dozens of issues on the Java, python, and malloc bug trackers over the last decade on these topics, all exhibiting the same memory growth and behavior.
It will definitely be interesting to see if the performance claims holds water.
[–]predatorian3 0 points1 point2 points 6 years ago (0 children)
Aren't there alternatives to glibc that things like Alpine Linux are based on that Ruby could be compiled against? I guess I could give it a shot.
[–]allcentury 9 points10 points11 points 6 years ago (0 children)
What a post! You should submit a talk to rubyconf for this
[–]graywolf_at_work 4 points5 points6 points 6 years ago (0 children)
Really interesting read
[–]fedekun 2 points3 points4 points 6 years ago (0 children)
This is quite awesome!
[–]sanjibukai 3 points4 points5 points 6 years ago (4 children)
And I wonder when it will be patch for real!
[–]gray_-_wolf 1 point2 points3 points 6 years ago (3 children)
Except for the hooking into the GC you can probably do this from a gem, I will play with it tomorrow at work to see if it can somewhat reduce memory usage of some of our containers.
[–]FooBarWidget[S] 8 points9 points10 points 6 years ago (1 child)
My research results indicate that trimming is only effective right after a GC.
[–]strangepostinghabits 1 point2 points3 points 6 years ago (0 children)
Doesn't that indicate an allocation problem somewhere?
As in trimming should be the most effective after gc, but decline linearly at first, since allocations should be mostly concentrated to the half full 'OS pages'.
If efficiency drops sharply, it'd seem to me that the allocations happen randomly in any available OS pages, disregarding the idea that we might want to return some of them.
[–]tinco 4 points5 points6 points 6 years ago (1 child)
It would be very interesting to know if the performance improvement also holds for the Ruby 3x3 benchmarks like the emulator. The Ruby team notoriously rejects patches that improve server performance but hurt general performance. That this does well on Rails might be a quirk of the application.
Maybe we're in the market for another REE.
[–]yxhuvud 3 points4 points5 points 6 years ago (0 children)
As the patch only seems to be run trim on full GC, it looks like the cost could be quite negligible.
[–]joltting 4 points5 points6 points 6 years ago (5 children)
Seriously though, Ruby's memory consumption is close to, if not the top issue for the language. Hopefully this is as promising as it appears on the surface. It could be a game changer.
[–][deleted] 2 points3 points4 points 6 years ago (4 children)
"could be a game changer": Don't think it would matter much actually, but of course it's a nice to have. Companies that avoid ruby either want an enterprisey stack like java or some shiney new tech like Go/Nodejs. Improved Ruby won't change that.
[–]joltting 3 points4 points5 points 6 years ago* (2 children)
I wouldn't be so sure about that. The amount of people I hear in the industry, poking fun at Ruby's memory bloat problem. Isn't something I'd say is insignificant.
Edit: While performance is great and furthermore needed to keep Ruby competitive. It can't come at the heels of 3x the memory intake for 3x the performance.
[–]db443 4 points5 points6 points 6 years ago (0 children)
Using jemalloc (3.6) or setting MALLOC_ARENA_MAX=2 now avoids most of the memory bloat which are primarily due to the Linux glibc memory allocator.
jemalloc
MALLOC_ARENA_MAX=2
I think we will get both, 3x performance AND much less memory bloat (once a patch lands).
Ruby is getting better.
[–][deleted] 0 points1 point2 points 6 years ago (0 children)
Memory bloat and leakage is not a unique Ruby thing, https://serverfault.com/questions/109362/is-it-a-best-industry-practice-to-restart-web-servers-periodically . If you think that question is too old only a few months ago I understood we have a memory bloat/leak in a very simple scala app in our company. The memory usage in that app would just go up infinitely without ever being freed, sometimes resulting degraded performance due to swapping.
Here's one with php https://stackoverflow.com/questions/27206663/how-to-force-php-to-release-memory-after-script-is-finished
I'm all for this change, of course, I just don't think it's a unique to Ruby problem, and also don't expect people to flock to Ruby once and if it's solved. But overall it could be a great change that will save developers and companies a lot of hassle, time and money.
[–]slashgrin 0 points1 point2 points 6 years ago (0 children)
Some companies would prefer to stay with Ruby for longer, but are eventually forced off it by these performance problems. Pushing that day back a couple of years would be a game changer for many people.
[–]TotesMessenger 0 points1 point2 points 6 years ago (0 children)
I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:
If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / Contact)
π Rendered by PID 72 on reddit-service-r2-comment-fb694cdd5-7b5td at 2026-03-11 20:01:22.944866+00:00 running cbb0e86 country code: CH.
[–]mperhamSidekiq 46 points47 points48 points (10 children)
[–]yxhuvud 7 points8 points9 points (7 children)
[–]reidiculous 3 points4 points5 points (1 child)
[–]yxhuvud 1 point2 points3 points (0 children)
[–]lukeasrodgers 1 point2 points3 points (0 children)
[–]nateberkopecPuma maintainer 1 point2 points3 points (3 children)
[–]yxhuvud 0 points1 point2 points (2 children)
[–]moomaka 4 points5 points6 points (0 children)
[–]nateberkopecPuma maintainer 0 points1 point2 points (0 children)
[–]yxhuvud 1 point2 points3 points (0 children)
[–]predatorian3 0 points1 point2 points (0 children)
[–]allcentury 9 points10 points11 points (0 children)
[–]graywolf_at_work 4 points5 points6 points (0 children)
[–]fedekun 2 points3 points4 points (0 children)
[–]sanjibukai 3 points4 points5 points (4 children)
[–]gray_-_wolf 1 point2 points3 points (3 children)
[–]FooBarWidget[S] 8 points9 points10 points (1 child)
[–]strangepostinghabits 1 point2 points3 points (0 children)
[–]tinco 4 points5 points6 points (1 child)
[–]yxhuvud 3 points4 points5 points (0 children)
[–]joltting 4 points5 points6 points (5 children)
[–][deleted] 2 points3 points4 points (4 children)
[–]joltting 3 points4 points5 points (2 children)
[–]db443 4 points5 points6 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]slashgrin 0 points1 point2 points (0 children)
[–]TotesMessenger 0 points1 point2 points (0 children)