Skip to content

cache: reduce contention in load_or_fetch by removing write lock from slow I/O paths #7

Closed

Description

@blackopsrepl

Problem

load_or_fetch currently holds the global cache write lock while checking files, reading disk, fetching from Overpass, and writing cache files.

Why this matters

This serializes unrelated callers and can create poor concurrency under load.

Scope

  • Refactor to use double-checked insertion.
  • Consider per-key in-flight fetch deduplication.
  • Only hold the write lock for insertion/replacement.

Acceptance criteria

  • Slow I/O is performed outside the global cache write lock.
  • Concurrent callers for different regions do not block each other unnecessarily.
  • Duplicate fetches for the same region are either prevented or explicitly handled.

Activity

  1. blackopsrepl commented on Mar 21, 2026

    @blackopsrepl
    ContributorAuthor

    Resolved by #20.

    load_or_fetch now performs slow file and network I/O outside the global cache write lock, while same-key callers share one in-flight load and different keys no longer serialize unnecessarily.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions