TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Faster Ruby: Thoughts from the outside

242 pointsby pvsukale3almost 3 years ago

17 comments

jrochkind1almost 3 years ago
&gt; What kind of speedup is available for big Rails applications? If 90% of the time in an application is spent in database calls, then there’s little opportunity for improvement via JIT technologies.<p>This is written as speculation of course, but it matches some long-time &quot;conventional wisdom&quot;, that most Rails apps spend most of their time on I&#x2F;O waiting for something external.<p>That may have been true once, but i don&#x27;t believe it&#x27;s true anymore.<p>My Rails apps now, when things like &quot;n+1 database query problems&quot; are properly eliminated, all spend more of their time on CPU than I&#x2F;O, 60-80%. (I think most of that CPU time is ActionView rendering. Unsure about CPU parts of ActiveRecord, that aren&#x27;t waiting on DB, but converting db results to in-memory AR objects etc).<p>When this comes up and I ask around on social media who else has actually looked at their app and can confirm or deny, almost all who respond agree. I would be curious to see here too.<p>Definitely some more systematic rather than anecdotal investigation is called for. But I think it&#x27;s time to stop repeating that it&#x27;s likely that a Rails app is I&#x2F;O-bound rather than CPU-bound, my experience leads me to think the reverse is currently likely.<p>[*edit* after I wrote this comment, I noticed <i>multiple</i> other comments in this thread saying basically the same thing. OK, so. Can we put this rumor to rest?]
评论 #32411553 未加载
评论 #32410772 未加载
评论 #32410681 未加载
评论 #32411199 未加载
评论 #32415123 未加载
评论 #32411209 未加载
评论 #32417914 未加载
评论 #32410682 未加载
评论 #32418435 未加载
girishsoalmost 3 years ago
After almost 4 years, I recently started working on a small Rails app. Typical Rails responses used to take hundreds of milliseconds before, now it takes tens of milliseconds (with latest versions). I was not expecting that at all. Together with turbo and stimulus, responses seem almost instant. Kudos to the Ruby and Rails teams.<p>I am definitely excited about Ruby&#x2F;Rails again!
评论 #32409759 未加载
chrisseatonalmost 3 years ago
&gt; If 90% of the time in an application is spent in database calls<p>This is what a lot of people say, but I&#x27;m not sure that this is the case.<p>I think apps spend about 50-70% of their time in compute in the interpreter, at the low end.<p>People don&#x27;t often make metrics from their apps public, but here&#x27;s one example from a web site that renders text - so it&#x27;s reading from the database and not doing some unusually computational task with the result <a href="https:&#x2F;&#x2F;genius.com&#x2F;James-somers-herokus-ugly-secret-annotated" rel="nofollow">https:&#x2F;&#x2F;genius.com&#x2F;James-somers-herokus-ugly-secret-annotate...</a>.
评论 #32409094 未加载
评论 #32410435 未加载
评论 #32409881 未加载
评论 #32408991 未加载
评论 #32409041 未加载
boesboesalmost 3 years ago
&gt;What kind of speedup is available for big Rails applications? If 90% of the time in an application is spent in database calls, then there’s little opportunity for improvement via JIT technologies.<p>This has always been the premise for enabling multi-threading on RoR applications despite the GIL. The convertional wisdom is you spend 80-90% of time waiting for the DB and other IO. After 15 years of hosting rails applications, I&#x27;m pretty sure that is not generally true for real world applications.<p>It depends on the application obviously how this works out, but for a larger, complex saas app I work on it works out to 64% ruby time for web requests. For another application, that does a lot more external calls, it&#x27;s 52%.<p>So raw performance of ruby can have a pretty significant impact on real performance for RoR applications. To the point where a faster CPU (new gen on AWS) improved response times by 15-20% for us.
评论 #32409661 未加载
评论 #32409368 未加载
drewbug01almost 3 years ago
I would summarize the article as:<p>- Ruby would benefit from object shapes and JIT compiling<p>- Good news, both of those are being added &#x2F; improved<p>- The jury is out about C extensions<p>I hope ruby has a renaissance in the next few years. People can and will howl about its performance, but it’s <i>far</i> faster than it was even a few years ago, let alone 10. The changes mentioned in the article, the async gem, and ractors are all exciting things that could push it even faster and unlock previously unavailable design patterns.<p>Byte for byte, it’s one of the nicest languages (in my opinion of course), and for many use-cases Rails is like having developer superpowers.<p>I hope renewed excitement leads to more investment from folks, because it’s honestly just such a nice, ergonomic ecosystem to use.
评论 #32413803 未加载
评论 #32410406 未加载
评论 #32415890 未加载
aardvark179almost 3 years ago
Since several people are chiming in with suggestions for what might make rails slow I will throw in my two pence.<p>Profile things, and make sure you understand the results of the profile (because profilers can lie to you in a whole variety of ways).<p>When I last checked on TruffleRuby some time ago the slowest thing on a small rails app was all the layers of framework and all the points at which it might log things, while the actual database access and the use of that data was pretty quick.<p>This might not continue to be true for larger applications, but it probably means there is a high minimum amount of work that must be done per request, and it’s so deep on the stack that it’s unlikely to be optimised away.<p>The situation may have improved, we’ve done a lot of work on TruffleRuby since then and completely changed the inlining strategy at least once, and the method lookup and dispatch. But the profiler has also changed significantly so the way it lies will also be different now.
评论 #32409589 未加载
dwheeleralmost 3 years ago
I think implementing shapes is very likely to significantly improve the raw compute speed of Ruby applications.<p>That said, if you&#x27;re implementing an application in Rails, there are a number of low-hanging fruit that will significantly improve performance. In most cases they&#x27;d apply in <i>any</i> language, but since it&#x27;s trivial to get &quot;something running&quot; in Rails, it&#x27;s easy to forget the basics for performance. E.g.:<p>* Index your database for all queries that matter.<p>* Use caches. In the case of Rails, use partials; they are <i>amazingly</i> effective at improving performance.<p>* Use a tool to detect N+1 queries, and fix them.<p>* When querying with an ORM (ActiveRecord in Rails), request just the specific fields you need instead of &quot;downloading everything&quot; into the object. Getting unnecessary fields increases the database response, the memory use, and the garbage collection effort, and all of that unnecessary work eventually adds up.<p>In general, you can get a lot of performance improvements by doing only what needs to be done and nothing else. Caching to avoid repeated work, requesting only the data you need, etc., can provide a lot of performance improvement and often require relatively little effort.
citrin_rualmost 3 years ago
&gt; If 90% of the time in an application is spent in database calls, then there’s little opportunity for improvement via JIT technologies.<p>Even if it is true (for a given application) it doesn&#x27;t mean that you don&#x27;t need to optimize CPU usage. It&#x27;s just mean that you may run out of RAM first (if you don&#x27;t use async I&#x2F;O) before you&#x27;ll saturate CPU. Or may not.<p>First, in most non small projects database and app (e. g. Ruby) layers usually either use separate hardware or shared HW but we can account hardware cost for each of them. If DB layer uses much more HW than app layer then yes, it makes little sense to reduce CPU usage by Ruby. But usually an app layer is bigger, especially if a language like Ruby is used. Let&#x27;s focus on the app layer assuming our DB layer works well (request latency can be non negligible - if it is stable under any load we have - that&#x27;s fine). Assume we need N servers with Ruby - let&#x27;s look what prevents us from using N&#x2F;2 servers and saving money: for web apps it is either CPU or RAM (disk I&#x2F;O handled by DB layers, 10Gbit network bandwidth should not be a bottleneck in most cases). For contemporary server hardware and web apps in my experience it is more common to saturate CPU before you&#x27;ll run out of RAM so by reducing CPU usage you can save money. But your mileage may vary.
Syzygiesalmost 3 years ago
I love Ruby so much as a scripting language, I ask myself why I don&#x27;t just use it as an &quot;acceptable lisp&quot; [1] for my research, rather than Haskell. Haskell is more easily parallelized than any other language I&#x27;ve experienced. Alas, my experiments with Ruby 3.1 parallel extensions flunked. Who cares about single core speed?<p>I was always put off by Rust syntax (it&#x27;s a fly-pollinated flower, to attract C programmers), but I&#x27;m starting to get the genius in its machine model. Learning Rust forces one to understand what&#x27;s happening at the machine level, but offers better control as a reward. Its expressiveness is a lot closer to Ruby than I had imagined, it won&#x27;t put me back in the C99 stone ages. So my provisional answer is that Rust is a Faster Ruby.<p>[1] <a href="http:&#x2F;&#x2F;www.randomhacks.net&#x2F;2005&#x2F;12&#x2F;03&#x2F;why-ruby-is-an-acceptable-lisp&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.randomhacks.net&#x2F;2005&#x2F;12&#x2F;03&#x2F;why-ruby-is-an-accepta...</a>
评论 #32415749 未加载
评论 #32415537 未加载
iziettoalmost 3 years ago
I think that one underrated point about web apps performance is JSON serialization for non-JS languages. JavaScript is obviously fast with that, but non-JS languages exposing API, like Rails in a separated FE&#x2F;BE architecture, spend much time transforming data into JSON, and it doesn&#x27;t seem stressed enough to me.
评论 #32409425 未加载
exabrialalmost 3 years ago
Another thing though: If at least one of your constraints are speed, a dynamically language probably shouldn’t be your first choice. If you need to maintain memory safety, Java or Rust would be more applicable.<p>That being said, once you have a codebase written in a certain language, you might just be stuck there due to hired talent being familiar with it. I don’t think I’ve really seen a company pull off a polygot move cheaply. Instead, a parallel move to something like Crystal may require minimal re-training.<p>… just thoughts I would have if I were in charge of investing R&amp;D time at a large org like the ones mentioned in the article.
评论 #32411147 未加载
评论 #32410871 未加载
评论 #32410820 未加载
tomphooleryalmost 3 years ago
&gt; What kind of speedup is available for big Rails applications?<p>When working with both ActiveRecord and Mongoid, I noticed that the vast majority of time spent outside of the database is in runtime type-checking and type conversion. That is, when an object is passed in from the DB, it takes the model a bit of time to get all of the data set up correctly. This doesn&#x27;t become a huge problem unless you have a lot of embedded data in the record, which tends to happen more frequently in MongoDB.
cercatrovaalmost 3 years ago
Somewhat related, what do people think of Crystal (a compiled language with types with Ruby-like syntax)? How is it for web applications? Is there a Rails equivalent for it yet?
评论 #32415117 未加载
thdespoualmost 3 years ago
Don&#x27;t underestimate the cost of ORMs. The serialisation&#x2F;parsing to models can make a significant performance impact.
评论 #32409737 未加载
评论 #32409377 未加载
评论 #32409509 未加载
transfirealmost 3 years ago
“Just throw a compiler at it!”<p>If you really want a speed bump then that’s exactly what you want to do. And I think Ruby’s overlooking a golden opportunity to join forces with Crystal.
评论 #32409748 未加载
评论 #32410638 未加载
ksecalmost 3 years ago
I am pretty sure Shopify is still hiring. May be the author wants to work on next gen Ruby VM as well?
评论 #32414861 未加载
Dowwiealmost 3 years ago
Isn&#x27;t Elixir a &quot;faster ruby&quot;?
评论 #32412421 未加载
评论 #32412139 未加载
评论 #32410868 未加载