Memory leak caused by diffs?
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 2.3k
- Forks
- 293
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the reduced Ruby script against the Rails repository and monitoring memory while repeated parent.diff calls execute. Then trace the Rugged/libgit2 diff path to identify which allocations remain live between iterations. Done means repeated diff generation no longer shows steady memory growth, with the reproduction used to verify the result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, git, ruby
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100