Skip to content

Commit

Permalink
Minor revision to mutex calls
Browse files Browse the repository at this point in the history
After some benchmarking, it seems this locking pattern leads to slightly
faster runtimes than just holding the lock for the entire function. The
benchmark is a pathologic case though where manifests in all content
pieces are duplicates of each other due to concurrent compaction.
  • Loading branch information
ashmrtn committed Aug 13, 2024
1 parent 9e127dd commit 9315ffd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions repo/manifest/committed_manifest_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,13 @@ func (m *committedManifestManager) loadCommittedContentsLocked(ctx context.Conte
ci.ContentID,
func(e *manifestEntry) bool {
mu.Lock()
defer mu.Unlock()

prev := committedEntries[e.ID]
mu.Unlock()

if prev == nil || e.ModTime.After(prev.ModTime) {
mu.Lock()
committedEntries[e.ID] = e
mu.Unlock()
}

// Continue iteration.
Expand Down

0 comments on commit 9315ffd

Please sign in to comment.