Skip to content

perf: fast paths for Thread.current, Fiber.current, Mutex#synchronize #381

Description

@linyiru

Part of #378.

shape rubyrs CRuby 3.4 ×
Thread.current 150 25 6
Thread.current[:k] 248 27 9
Mutex#synchronize {} 1257 53 24

Per Rails request there are about 20 Thread.current and about 15 Fiber.current calls. IsolatedExecutionState, CurrentAttributes, the logger and Concurrent::Map all go through them. Monitor/Mutex sit on the logger and cache paths.

Do:

  • Profile each path with sample.
  • Serve Thread.current and Fiber.current as cached handles (no lookup or allocation per call).
  • Make Thread#[] / #[]= direct fiber-local table reads.
  • Make Mutex#synchronize a native lock/yield/ensure-unlock, with no Ruby-level begin/ensure frame.

Done when:

  • Each shape is within 2× of CRuby.
  • Existing Thread/Fiber/Mutex specs pass.
  • A diff_cruby fixture covers fiber-local vs thread-local semantics.

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

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions