rugged: Memory leak caused by diffs?
I’m using Rugged in an application that uses Rugged to generate thousands of diffs in quick succession, and I’m noticing memory growing steadily as it runs.
I’ve managed to reproduce the problem in this reduced test case, which just generates a lot of diffs with a big repo (rails/rails). You can run this script and watch the memory consumption just go up and up and up.
require "rugged"
def diff_parents(commit)
puts commit.oid
commit.parents.each { |parent| parent.diff(commit) }
commit.parents.each { |parent| diff_parents(parent) }
rescue SystemStackError # This can hit Ruby's recursion limit. Just move on.
end
path = "#{__dir__}/rails"
if File.directory?(path)
repo = Rugged::Repository.new(path)
else
print "Cloning rails…"
repo = Rugged::Repository.clone_at("https://github.com/rails/rails", path)
puts " done"
end
diff_parents repo.head.target
I don’t have the C knowledge to figure out the cause of the leak, so this could be a libgit2 issue rather than a Rugged-specific one.
About this issue
- Original URL
- State: open
- Created 7 years ago
- Comments: 19 (18 by maintainers)
Commits related to this issue
- Add call to Repository#close Might help with memory usage for RunUndercover https://github.com/libgit2/rugged/issues/695 — committed to grodowski/undercover-ci by grodowski 5 months ago
Awesome, thanks for the graph. I just wanted to comment and say I haven’t forgotten about this, just been busy with life stuff (RailsConf last week, moving this week). I’ll continue poking at this on Thursday. I believe @kivikakk was able to write a repro in C, so we might be able to eliminate Ruby from the equation.