Skip to content

runtime: avoid a heap allocation in semacquire - #6860

Open
davecheney wants to merge 1 commit into
tinygo-org:devfrom
davecheney:sema-task-queue
Open

davecheney wants to merge 1 commit into
tinygo-org:devfrom
davecheney:sema-task-queue

Conversation

@davecheney

@davecheney davecheney commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

semacquire allocated a semaWaiter on the heap each time the first canSemacquire call failed, because enqueue stored its address in semtable.

The cooperative and cores sleep queues and sync.Cond already use Task.Next and Task.Data. A blocked task waits in one queue only, so the semaRoot queue can use these fields.

With this change, semacquire does not allocate. The //go:noheap pragma on semacquire causes a build error if a later change adds a heap allocation to it.

@davecheney
davecheney requested a review from jakebailey December 6, 2026 00:59
@davecheney
davecheney marked this pull request as ready for review December 6, 2026 00:59
semacquire allocated a semaWaiter on the heap each time the first canSemacquire call failed, because enqueue stored its address in semtable.

The cooperative and cores sleep queues and sync.Cond already use Task.Next and Task.Data. A blocked task waits in one queue only, so the semaRoot queue can use these fields.

With this change, semacquire does not allocate. The //go:noheap pragma on semacquire causes a build error if a later change adds a heap allocation to it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant