Repository navigation
perf: keep each green task's join, closure and threadlocals in its sync block - #1235
Merged
Merged
Conversation
# Conflicts: # cranelift/runtime/src/concurrency/green.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1233.
A spawn plus an await took about a dozen lock/unlock pairs and three allocations per task:
Arc<(Mutex, Condvar)>and a boxed threadlocal map;green_fanoutwas 3.6x Go.Task state moves into the task's
SyncBlock. These blocks sit in an arena whose chunks never move or free. The join (generation, done, result, waiters, OS-thread waiter count, behind one small mutex and a condvar), the threadlocal map and the closure now live there inline.(index, generation). Await, detach andis_donecheck the generation (and aliveflag) under the join lock, so a stale or garbage handle resolves to nothing. That makes the registry lookups redundant for green tasks.Thread-owned worker cache. Each worker's stack and id cache sits behind an owner-only cell. A separate thread-local, which only
worker_loopsets, keys it, so a test or probe posing as a worker uses the locked shared pools instead.Thieves skip held queues. A thief or injector popper that finds a queue locked moves on instead of blocking. 15 idle workers used to queue up in the kernel on one mutex. The queue's atomic length still reads non-zero, so no worker parks while work remains.
steal_halfalso no longer allocates aVecper steal.green_fanout(2M spawn+await in batches of 64), ms:Tried and dropped: a short spin before an OS-thread await blocks. It was 4% faster at 4 workers and 6% slower at 16.
Local corpus, leak, memcheck, green, result-box, cargo test, seed, TLS-barrier and panic gates pass. The slab unit tests are replaced by lifecycle tests: retiring on await, stale generations, and detaching running and finished tasks.