Ahoy all! 🚢 Step aboard as we cruise through the Rails news this week. Summer has really hit its simmering point for many a Rails contributor: we’re seeing fewer contributions. Take heed! Your trusty captain Kasper is here to reassure you that nothing has gone wrong on this ship and that it’s merely summer time seasoning. But also, the engine is on fire? Oh well, it’ll probably burn out soon enough and another wrong has been righted! This is fine. 🔥
This week has primarily been a strong one for Active Record’s schema cache with no less than 3 improvements. It’s a little known feature but it avoids querying your database for its schema every time a new server starts up (handy if you’re booting up many app servers). You invoke it with…
rails schema:cache:dump, check its documentation for more. These 3 changes are around deduplication the memory that the schema cache holds in a running app by doing deduplication. Basically running a uniq on objects and reusing already initialized ones. This technique is uncommon, but effective here, because so many tables share the same columns, e.g. id, created_at, updated_at etc. So the first change…
…ran deduplication for most things in the schema cache. The second change skipped storing the columns_hash in the YML, because it could be derived with columns.index_by(&:name). Thus saving storing every column object again, but just nested under the name. Neat! Rounding out the features: the deduplication should also be run when parsing YML and the parser invoking init_with. Remedied that, phew! I suggest you do check all three changes out because they show to really re-sculpt a feature over multiple PRs.
Lastly, rounding out the news: some more speed ups! Currently serializing a Time attribute will run time.getutc in multiple places regardless of whether the time is already UTC, which is fairly expensive. This change checks if the time is already UTC and won’t bother with any needless conversion. ⏱
21 people contributed to Rails in the last two weeks. You can see the full list of changes here.
Until next time!