Really solid list! I went through all the Active Record, query design, and index design tips for PostgreSQL, and can +1 them all. Nice work. For readers who want all of these and more in book form, with a sample Rails app and big data to test with (generated), please consider my book: High Performance PostgreSQL for Rails https://news.ycombinator.com/item?id=38407585 The book helps readers build database skills with…
Thanks. I bought your book since the B1.0 version and I recommend it.
Everyday performance rules for Ruby on Rails developers
21–30 of 41 posts
Re: Everyday performance rules for Ruby on Rails developers
#22Some good advice here, but the “don’t index boolean columns” needs an “it depends” caveat, since Postgres will sometime use multiple boolean indexes to perform a bitmap index scan, which can be advantageous.
If the boolean values are not 50%/50% but skewed like 1%/99% then there can be a big advantage in using a partial index CREATE INDEX index_accounts_balance ON accounts (id) WHERE boolean_flag;
Re: Everyday performance rules for Ruby on Rails developers
#23I can't even read the site with that text contrast. Why is illegibility a trend at all?
Re: Everyday performance rules for Ruby on Rails developers
#24Re: Everyday performance rules for Ruby on Rails developers
#25Earlier quoted context omitted.
Or simpler, why do you need a CDN? It's rarely worth the additional work (setup + deployment) when most websites are not limited by bandwidth for assets.
If you're serving assets directly from S3 (or even from nginx) you're exposed to a "denial of wallet" attack, given the price markup on outbound networking.
Their point stands: if you don't have a reason to use a CDN, don't use a CDN
Re: Everyday performance rules for Ruby on Rails developers
#26Good stuff but the `size`, `count`, `length` section just intensifies my dislike for ORMs. ORMs bury all of the SQL, just for devs to dig it back up when they realize it's important for performance. Now you have to be a SQL expert and an ActiveRecord expert.
More concretely, performance is on my list of "good problems to have". Businesses die in the time it takes to write raw SQL.
Re: Everyday performance rules for Ruby on Rails developers
#27Good stuff but the `size`, `count`, `length` section just intensifies my dislike for ORMs. ORMs bury all of the SQL, just for devs to dig it back up when they realize it's important for performance. Now you have to be a SQL expert and an ActiveRecord expert.
I don't want to live in a world where I can't pop into a Rails console and run something like `Foo.joins(:bars).any?`. More concretely, performance is on my list of "good problems to have". Businesses die in the time it takes to write raw SQL.
Re: Everyday performance rules for Ruby on Rails developers
#28I assume this is telling us it doesn't actually make an ActiveRecord instance out of each row when you do that. And instantiating big bunches of ActiveRecord model instances just to grab a few fields from a result set with a lot of rows can be sooo slow.
Re: Everyday performance rules for Ruby on Rails developers
#29Really glad to see more basic Ruby / Rails content showing up on HN!!!
Re: Everyday performance rules for Ruby on Rails developers
#30The hint about using .pluck to only grab what you need from an ActiveRecord query is a pretty good one. I hand't realized you could do that. I assume this is telling us it doesn't actually make an ActiveRecord instance out of each row when you do that. And instantiating big bunches of ActiveRecord model instances just to grab a few fields from a result set with a lot of rows can be sooo slow.