Live data from Hacker News

Reducing Memory Usage in Ruby

tenderlovemaking.com

11–20 of 58 posts

Re: Reducing Memory Usage in Ruby

#11

This is orthogonal to tenderlove's GC work, but if you're using MRI and want an easy memory usage/performance win, swap out the standard glibc malloc for jemalloc: https://www.levups.com/en/blog/2017/optimize_ruby_memory_usa...

Kind of a tangent, but does anyone know why glibc’s allocator loses to jemalloc on common workloads? I would expect that would be something worth rectifying unless other requirements tie their hands.

Re: Reducing Memory Usage in Ruby

#12

This is orthogonal to tenderlove's GC work, but if you're using MRI and want an easy memory usage/performance win, swap out the standard glibc malloc for jemalloc: https://www.levups.com/en/blog/2017/optimize_ruby_memory_usa...

Kind of a tangent, but does anyone know why glibc’s allocator loses to jemalloc on common workloads? I would expect that would be something worth rectifying unless other requirements tie their hands.

Quite a few complaints about jemalloc from Rust, where people wonder about higher than necessary memory usage

jemalloc likely wins more for the kinds of allocations you find in scripting language runtimes, which also happens to be similar to a browser given DOM & JS

See also: https://sourceware.org/glibc/wiki/389-ds-malloc

Re: Reducing Memory Usage in Ruby

#13
post #10
post #5

Earlier quoted context omitted.

Exactly. As a Ruby developer, Crystal makes me itch . It jettisons exactly what Ruby is valuable to me for: quickly and dynamically building fluent-feeling libraries and tools. It's fast, but I don't need fast--if I don't need Ruby's metaprogramming, I have other, better, established languages to use for those tasks. (Kotlin, C#, Rust, whatever.) Elixir is kind-of in the same boat for me. I think it's neat and has it…

Have you used a recent (2017) version of Crystal? Quickly building fluent-feeling libraries and tools is exactly my use case for Crystal. For me, everything that Ruby is valuable for is retained. I'm able to do all the things I did in Ruby just fine, and it prevents me from doing a lot of things I shouldn't have been doing. We recently migrated our app from Rails to Crystal (using the Amber framework) and our code ba…

Until I can perform runtime define_method calls and dynamically construct classes, it doesn't matter what Crystal does. It's fundamentally antithetical to my needs. (JavaScript isn't, but JavaScript is kind of clunky.)

I have Kotlin, C#, C++, and Rust if I need static typing. Ruby is for when I don't.

Re: Reducing Memory Usage in Ruby

#14
post #13
post #10

Earlier quoted context omitted.

Have you used a recent (2017) version of Crystal? Quickly building fluent-feeling libraries and tools is exactly my use case for Crystal. For me, everything that Ruby is valuable for is retained. I'm able to do all the things I did in Ruby just fine, and it prevents me from doing a lot of things I shouldn't have been doing. We recently migrated our app from Rails to Crystal (using the Amber framework) and our code ba…

Until I can perform runtime define_method calls and dynamically construct classes, it doesn't matter what Crystal does. It's fundamentally antithetical to my needs. (JavaScript isn't, but JavaScript is kind of clunky.) I have Kotlin, C#, C++, and Rust if I need static typing. Ruby is for when I don't.

How late at runtime do these dynamic definitions need to be possible? Just at startup or also after the program has been running for a while?

I occasionally wonder whether it might be possible to accommodate more dynamic language features with a compiler that treats them like a macro system that is expanded statically, such that no actual dynamicism is necessary at runtime.

Re: Reducing Memory Usage in Ruby

#15

What I'd like to be able to do is load ActiveRecord (or any other v. heavy lib) asynchronously in non web-based apps so that I can paint the UI quicker. By the time the user will do/need anything db-related a proxy object should be swapped out for an actual ActiveRecord object. Using Rails' ORM is so nice and ergonomic but it kills start-up time with all the file requires, Bootsnap helps a bit but I'd prefer not to h…

I am actually facing a similar problem. I also find that Rails just creates a db connection everytime I do Model.new even though I have not yet saved it.

Re: Reducing Memory Usage in Ruby

#16

What I'd like to be able to do is load ActiveRecord (or any other v. heavy lib) asynchronously in non web-based apps so that I can paint the UI quicker. By the time the user will do/need anything db-related a proxy object should be swapped out for an actual ActiveRecord object. Using Rails' ORM is so nice and ergonomic but it kills start-up time with all the file requires, Bootsnap helps a bit but I'd prefer not to h…

I don’t quite understand why this is a problem. You pay the ActiveRecord boot time once, at app start, and then it’s no longer an issue.

Re: Reducing Memory Usage in Ruby

#17
post #13
post #10

Earlier quoted context omitted.

Have you used a recent (2017) version of Crystal? Quickly building fluent-feeling libraries and tools is exactly my use case for Crystal. For me, everything that Ruby is valuable for is retained. I'm able to do all the things I did in Ruby just fine, and it prevents me from doing a lot of things I shouldn't have been doing. We recently migrated our app from Rails to Crystal (using the Amber framework) and our code ba…

Until I can perform runtime define_method calls and dynamically construct classes, it doesn't matter what Crystal does. It's fundamentally antithetical to my needs. (JavaScript isn't, but JavaScript is kind of clunky.) I have Kotlin, C#, C++, and Rust if I need static typing. Ruby is for when I don't.

You can do all of that with really easy to write crystal macros.

Re: Reducing Memory Usage in Ruby

#18
post #13
post #10

Earlier quoted context omitted.

Have you used a recent (2017) version of Crystal? Quickly building fluent-feeling libraries and tools is exactly my use case for Crystal. For me, everything that Ruby is valuable for is retained. I'm able to do all the things I did in Ruby just fine, and it prevents me from doing a lot of things I shouldn't have been doing. We recently migrated our app from Rails to Crystal (using the Amber framework) and our code ba…

Until I can perform runtime define_method calls and dynamically construct classes, it doesn't matter what Crystal does. It's fundamentally antithetical to my needs. (JavaScript isn't, but JavaScript is kind of clunky.) I have Kotlin, C#, C++, and Rust if I need static typing. Ruby is for when I don't.

People think "oh, it's compiled, so I can't have dynamic methods" but that couldn't be more far from the truth. You can do all of that at compile time, and Crystal provides an excellent way of doing so. E.g.: https://github.com/sam0x17/crystal-mongo-orm/blob/master/src...

Re: Reducing Memory Usage in Ruby

#19
post #14
post #13

Earlier quoted context omitted.

Until I can perform runtime define_method calls and dynamically construct classes, it doesn't matter what Crystal does. It's fundamentally antithetical to my needs. (JavaScript isn't, but JavaScript is kind of clunky.) I have Kotlin, C#, C++, and Rust if I need static typing. Ruby is for when I don't.

How late at runtime do these dynamic definitions need to be possible? Just at startup or also after the program has been running for a while? I occasionally wonder whether it might be possible to accommodate more dynamic language features with a compiler that treats them like a macro system that is expanded statically, such that no actual dynamicism is necessary at runtime.

This is exactly what crystal does

Re: Reducing Memory Usage in Ruby

#20
post #2

Or just use Crystal https://crystal-lang.org XD

Crystal is not a replacement for Ruby. In the same way that many Algol-like languages are not a straight swap for each other. Don't get me wrong, Crystal is a nice idea but say goodbye to all that yummy Ruby meta-programming which is one of the key things what makes the language so appealing in the first place.

Take a look at macros in crystal and I promise you 99% of the time you will be able to do what you did in Ruby. Practically everything people do that is "necessarily dynamic" could be done with macros at compile-time. You CAN do things like define the behavior for when a method name is unmatched on an Object or (at compile time) do some string processing and define a bunch of methods based on the results.
Post reply on HN