Memoize resource relationships

bin/bench_regression
  "version": "0.10.0.rc5",
  "rails_version": "4.2.6",
  "benchmark_run[environment]": "2.2.2p95",

perf/only_calc_associations_once
"commit_hash": "1e7c428",
caching on: caching serializers: gc off 741.7702402782281/ips; 1355 objects
caching on: non-caching serializers: gc off 712.3752615532874/ips; 1257 objects
caching off: caching serializers: gc off 706.0789199312495/ips; 1355 objects
caching off: non-caching serializers: gc off 751.5310710635379/ips; 1257 objects

master
"commit_hash": "1033b711c7d7c231bb5b832e7dfe7f99389f22c4"
caching on: caching serializers: gc off 567.7959835633892/ips; 1803 objects
caching on: non-caching serializers: gc off 776.4929551133658/ips; 1257 objects
caching off: caching serializers: gc off 538.046851190591/ips; 1803 objects
caching off: non-caching serializers: gc off 738.5596630209004/ips; 1257 objects
This commit is contained in:
Benjamin Fleischer 2016-04-18 09:31:38 -05:00
parent 4c0e2dcb28
commit b7e2bc06ed

View File

@ -34,7 +34,7 @@ module ActiveModelSerializers
def resource_relationships(options) def resource_relationships(options)
relationships = {} relationships = {}
serializer.associations(@include_tree).each do |association| serializer.associations(@include_tree).each do |association|
relationships[association.key] = relationship_value_for(association, options) relationships[association.key] ||= relationship_value_for(association, options)
end end
relationships relationships