Skip to content

4.0: one lock per container tree; drop use_lock #478

Description

@lesnik512

Observation

Every child container allocates its own threading.RLock. On this machine that is 107 ns of an 829 ns child build (13%), paid per request. The lock guards only singleton creation on a cache miss, which is rare after warm-up and already double-checked.

Proposal

One lock per tree, created at the root and shared by children (a child stores the reference, as it already does for the shared registries). use_lock goes away; a tree is always locked, and the cost is a pointer copy. Contention: concurrent cold misses across requests would serialise on one lock instead of per child, which is what the lock is for anyway.

Needs before it is ready

An end-to-end measurement on G6 (child build) and G15 (concurrent first-resolve, the contention scenario), plus a pass over the free-threading tests. The 107 ns figure is a microbenchmark of RLock() alone.

Out of scope

The _scope_map copy (another ~95 ns per child): walking parent_container instead moves the cost onto every cross-scope hop, and the trade is workload-dependent.

Activity

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

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions