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. β±