Skip to content

Instantly share code, notes, and snippets.

@kkismd
Last active March 2, 2017 03:25
Show Gist options
  • Save kkismd/64dc7c4e6302dfa1333c1a2375e2a952 to your computer and use it in GitHub Desktop.
Save kkismd/64dc7c4e6302dfa1333c1a2375e2a952 to your computer and use it in GitHub Desktop.
ActiveRecordのメモリ使用量を見積もりたい
require 'objspace'
module MemoryMesureable
extend ActiveSupport::Concern
included do
delegate :memsize_of, to: ObjectSpace
end
def memsize
memsize_of(self) +
memsize_of(@attributes) +
memsize_of(@association_cache) +
memsize_of(@aggregation_cache)
end
end
@kkismd
Copy link
Author

kkismd commented Mar 2, 2017

models/concerns に置いて、モデル側で include MemoryMesureable する

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