Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable most caching for packfile objects #854

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions gitindex/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,7 @@ func indexGitRepo(opts Options, config gitIndexConfig) (bool, error) {

// openRepo opens a git repository in a way that's optimized for indexing.
//
// It copies the relevant logic from git.PlainOpen, and enables the filesystem KeepDescriptors option. This
// caches the packfile handles, preventing the packfile from being opened then closed on every object access.
// It copies the relevant logic from git.PlainOpen, and tweaks certain filesystem options.
func openRepo(repoDir string) (*git.Repository, io.Closer, error) {
fs := osfs.New(repoDir)

Expand All @@ -612,7 +611,12 @@ func openRepo(repoDir string) (*git.Repository, io.Closer, error) {
}

s := filesystem.NewStorageWithOptions(fs, cache.NewObjectLRUDefault(), filesystem.Options{
// Cache the packfile handles, preventing the packfile from being opened then closed on every object access
KeepDescriptors: true,
// Disable caching for most objects, by setting the threshold to 1 byte. This avoids allocating a bunch of
// in-memory objects that are unlikely to be reused, since we only read each file once. Note: go-git still
// proactively caches objects under 16KB (see smallObjectThreshold in packfile logic).
LargeObjectThreshold: 1,
})

// Because we're keeping descriptors open, we need to close the storage object when we're done.
Expand Down
Loading