Skip to content

fixes performance regression with AR relations#34503

Closed
gingerlime wants to merge 1 commit intorails:masterfrom
gingerlime:fix_performance_regression_for_relations
Closed

fixes performance regression with AR relations#34503
gingerlime wants to merge 1 commit intorails:masterfrom
gingerlime:fix_performance_regression_for_relations

Conversation

@gingerlime
Copy link
Contributor

@gingerlime gingerlime commented Nov 21, 2018

  • See Recyclable cache keys #29092 (comment)
  • After introducing cache versioning, even with cache versioning off
    there's a performance regression when passing an Active Record
    relation to cache
  • This happens in ActiveSupport::Cache inside normalize_version
  • This method would check if the relation responds to cache_version
    and if not, would recrusively normalize it with to_a
  • This would lead to the relation being retrieved from database and
    enumerated, causing the performance regression
  • This fix simply adds cache_version returning nil to Active Record
    relations
  • This is a temporary stopgap, until relation cache versioning is
    implemented. See collection cache versioning #34378

* After introducing cache versioning, even with cache versioning off
  there's a performance regression when passing an Active Record
  relation to cache
* This happens in ActiveSupport::Cache inside `normalize_version`
* This method would check if the relation responds to cache_version
  and if not, would recrusively normalize it with `to_a`
* This would lead to the relation being retrieved from database and
  enumerated, causing the performance regression
* This fix simply adds `cache_version` returning `nil` to Active Record
  relations
* This is a temporary stopgap, until relation cache versioning is
  implemented. See rails#34378
@gingerlime gingerlime changed the title fixes https://github.com/rails/rails/pull/29092#issuecomment-437572543 fixes performance regression with AR relations Nov 21, 2018
@rafaelfranca
Copy link
Member

Thank you for the PR. We prefer to not implement stopgap solutions in the codebase. Let's wait for #34378

@gingerlime
Copy link
Contributor Author

This bug can cause quite severe performance regression from my experience, and it largely goes unnoticed, unless you actively measure performance. Hope that #34378 gets merged quickly and also backported, to fix existing versions of rails affected by this regression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants