Skip to content

perf(engine): replace assignedCountMu with atomic.Int64#4189

Open
salarkhannn wants to merge 6 commits into
hatchet-dev:mainfrom
salarkhannn:perf-atomic-assignedcount
Open

perf(engine): replace assignedCountMu with atomic.Int64#4189
salarkhannn wants to merge 6 commits into
hatchet-dev:mainfrom
salarkhannn:perf-atomic-assignedcount

Conversation

@salarkhannn

@salarkhannn salarkhannn commented Jun 15, 2026

Copy link
Copy Markdown

Description

Replaces assignedCount (int + sync.Mutex) with atomic.Int64 so the increment and read sequence is a single Add(1) call with no lock contention. This eliminates one mutex acquisition per task assignment on the scheduler hot path.

Type of change

  • Refactor (non-breaking changes to code which doesnt change any behaviour)

What's Changed

  • Replace assignedCount from int + sync.Mutex to atomic.Int64
  • Remove assignedCountMu from the scheduler struct

Checklist

Changes have been:

  • Tested (unit, integration, or manually with steps specified)
  • Linted and formatted

Related

goos: linux
goarch: amd64
cpu: 12th Gen Intel(R) Core(TM) i5-12450H

                      sec/op

AssignedCountMutex-12 40.71m ± 10%
AssignedCountAtomic-12 33.79m ± 13%

The atomic version is 17% faster (p=0.002, n=6). The block profile also confirms assignedCountMu.Lock() is eliminated after the change. All existing tests pass with the race detector enabled.


AI Disclosure
  • I acknowledge that an LLM was used in the creation of this Pull Request, in accordance with Hatchets AI_POLICY.md.

  • Details: used opencode for git workflows and formatting

@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown

@salarkhannn is attempting to deploy a commit to the Hatchet Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the engine Related to the core Hatchet engine label Jun 15, 2026
@salarkhannn salarkhannn reopened this Jun 15, 2026

@gregfurman gregfurman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @salarkhannn. I'm not certain you've read our contributing guidelines.

We require that a PR is:

  1. Linted and formatted.
  2. titled + scoped correctly following conventional commits format.
  3. AI usage disclosed.

For small changes like this, we're normally happy not requiring a linked issue. However, since this purports to improve performance, I'd like to see some more evidence before proceeding with a review.

Can you rework this PR to adhere to our guidelines and attach these benchmarks as additional information in the ## Related section following our https://github.com/hatchet-dev/hatchet/blob/main/.github/pull_request_template.md?

Comment thread pkg/scheduling/v1/scheduler.go Outdated
@salarkhannn salarkhannn changed the title scheduler: replace assignedCountMu with atomic.Int64 perf(engine): replace assignedCountMu with atomic.Int64 Jun 15, 2026
@salarkhannn

Copy link
Copy Markdown
Author

I'm sorry i didn't look at the contributing guidelines earlier. if there are any discrepancies, lmk

@salarkhannn salarkhannn requested a review from gregfurman June 15, 2026 14:47
Comment thread pkg/scheduling/v1/scheduler.go
@mnafees

mnafees commented Jun 19, 2026

Copy link
Copy Markdown
Member

@salarkhannn Can you please rebase with current main as some of these tests were fixed upstream?

assignedCount is only ever incremented and read under a single mutex
critical section. Replace the int+mutex pair with atomic.Int64 so the
increment-and-read sequence is a single Add(1) call with no lock
contention, eliminating one mutex acquisition per task assignment
on the scheduler hot path.
@salarkhannn salarkhannn force-pushed the perf-atomic-assignedcount branch from d4637e9 to a10363c Compare June 19, 2026 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine Related to the core Hatchet engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants