Skip to content

Read-only git operations acquire unnecessary index locks (GIT_OPTIONAL_LOCKS) #22047

Open

Description

@coleleavitt

The problem

Desktop runs multiple git commands concurrently (e.g., background fetch + foreground status + sidebar indicator refresh). Read-only operations like diff, log, and for-each-ref acquire the index lock by default, even though they don't modify the index. This causes lock contention and occasional failures when concurrent operations compete for the lock.

Proposed solution

Set GIT_OPTIONAL_LOCKS=0 environment variable for read-only git operations:

  • git diff (in diff.ts)
  • git log (in log.ts)
  • git for-each-ref (in for-each-ref.ts)

From git documentation:

When set to 0, Git will complete any requested operation without performing any optional sub-operations that require taking a lock. For example, this will prevent git status from refreshing the index as a side effect.

Desktop already sets --no-optional-locks on git status. This extends the same optimization to other read-only operations.

Additionally, for-each-ref can benefit from --count=10000 to cap output on repos with massive ref counts.

Release version

3.5.8 (x64)

Operating system

All platforms

Implementation in PR #22043.

Activity

  1. babakks commented on May 14, 2026

    @babakks
    Member

    Thanks for the detailed write-up, @coleleavitt! 🙏

    This looks like a reasonable optimization request. We already use --no-optional-locks for git status, so extending a similar approach to other read-only operations makes sense in principle. We're labeling this as an enhancement for now, but we'd like to look into it further to understand how much lock contention is actually happening in practice before committing to a change.

    A couple of notes:

    • Do you have evidence of actual lock failures or degraded performance caused by this? Logs, error messages, or timing data showing contention would help us prioritize this.
    • The --count=10000 suggestion for for-each-ref feels like a separate concern (output capping vs. lock avoidance).

    We'll leave this open for evaluation. Thanks again for the suggestion!

  2. added
    investigation-needed
    on May 14, 2026
  3. github-actions commented on May 14, 2026

    @github-actions
    Contributor

    Thank you for your issue! We have categorized it as an enhancement (feature or improvement) request, and it has been added to our backlog. In doing so, we are not committing to implementing this feature at this time, but, we will consider it for future releases based on community feedback and our own product roadmap.

    Unless you see the help wanted Issues marked as ideal for external contributors label, we are not currently looking for external contributions for this feature.

    If you come across this issue and would like to see it implemented, please add a thumbs up! This will help us prioritize the feature. Please only comment if you have additional information or viewpoints to contribute.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementinvestigation-needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions