-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[guides] 4.2 release notes: added technical details for Adequate Record #16844
Conversation
@@ -56,7 +56,59 @@ Rails 4.2 comes with a performance improvement feature called Adequate Record | |||
for Active Record. A lot of common queries are now up to twice as fast in Rails | |||
4.2! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should improve this paragraph a little bit too, a few issues with it:
- This is not so much of a "feature"... in the sense that it doesn't have a public interface and you don't need to do anything special to benefit from it, so it's more like a "refactor", or perhaps a "performance improvement"?
- "called Adequate Record" – you won't find that term anywhere in the code or in the documentation, so perhaps we should say something along that lines of "codenamed Adequate Record" instead.
- Nit: ending with a "!" seems a little bit too "exciting" for formal documentation? 😄
First of all, thank you so much for working on this! ❤️ Overall, I think this seems a little bit too detailed. I suggest that you take some inspiration from the Rails 4.1 release notes for the level of details. Upon reading those, it seems like they tend to follow the pattern of Specifically:
This is just a rough guideline of course 😄 For example, perhaps it makes sense to mention everything about the common find* queries and then mention the associations stuff at the end. There are probably other ways to structure this too, I'll leave it to you to explore – just remember the goal is to help the audience quickly answer those high-level questions quickly. Does it make sense? 😁 |
Thanks for the detailed feedback @chancancode. |
Here are some scenarios where the cache is not used - | ||
|
||
- `find` with a list of ids. eg- `Post.find(1,2,3)` or `Post.find([1,2])`. | ||
- `find_by` with a non hash argument. eg- `Post.find_by "published_at < ?", 2.weeks.ago`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this specifically for SQL fragments? (that might be more obvious phrase for people than 'non-hash argument')
1f4aee2
to
bb8eda4
Compare
Edited based on comments by @chancancode. Here's the new text: AdequateRecord is a set of refactorings that make ActiveRecord It works by caching SQL query patterns while executing the Activerecord calls. The cache helps skip parts of the computation involved in the transformation of the calls into SQL queries. More details in Aaron Patterson's post. Nothing special has to be done to activate this feature. Most Post.find 1 # caches query pattern
Post.find 2 # uses the cached pattern
Post.find_by_title 'first post' # caches query pattern
Post.find_by_title 'second post' # uses the cached pattern
post.comments # caches query pattern
post.comments(true) # uses cached pattern The caching is not used in the following scenarios -
|
Rails 4.2 comes with a performance improvement feature called Adequate Record | ||
for Active Record. A lot of common queries are now up to twice as fast in Rails | ||
4.2! | ||
AdequateRecord is a set of refactorings that make ActiveRecord `find` and `find_by` methods and some association queries upto 2x faster. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adequate Record
and Active Record
. We only use them in camel case when we are talking about the constants.
bb8eda4
to
00e30b8
Compare
Edited after @rafaelfranca's comments. |
[guides] 4.2 release notes: added technical details for Adequate Record
❤️ 💚 💙 💛 💜 |
Thanks @chancancode, @GeekOnCoffee, @rafaelfranca, you guys rock 🤘 🌟 ✨ |
Please review the changes as this is my first PR.
Edit:
Here's the added text for quick reference (second paragraph onwards):Added text is in the comment below
Adequate Record
Rails 4.2 comes with a performance improvement feature called Adequate Record
for Active Record. A lot of common queries are now up to twice as fast in Rails
4.2!
This feature caches SQL query patterns while executing some activerecord query methods. Activerecord queries are transformed into SQL before being executed, and this cache helps skip some computation involved in the transformation. More details in Aaron Patterson's post.
It affects the
find
andfind_by
query methods and association queries.The following call will cache the resultant query pattern, such that the next time there is a similar call, the pattern is re-used
Similarly for
find_by
:This cache is sometimes called the AST-cache (where AST is abstract syntax tree)
Here are some scenarios where the cache is not used -
find
with a list of ids. eg-Post.find(1,2,3)
orPost.find([1,2])
.find_by
with a non hash argument. eg-Post.find_by "published_at < ?", 2.weeks.ago
.Association queries too use a similar AST-cache. This cache is different from the association caching that already existed in Rails. For example
So the next time we invoke the
comments
method, we get the objects from the association cache. But if we force the query to get a refresh the comments, the AST-cache will be used: