Repository navigation
Conversation
Collaborator
Author
|
Assuming the mailbox is only going to contain 0-3 elements in the linked list I guess we could just drop the |
sbc100
force-pushed
the
intrusive_pthread_mailbox
branch
from
December 2, 2026 01:05
b58a409 to
eebdc3c
Compare
Following emscripten-core#28449, each `em_task_queue` only ever carries one pending notification in its target thread's mailbox at a time (coalesced via `NOTIFICATION_PENDING`) and already stays alive on the zombie list until `notification` transitions back to `NOTIFICATION_NONE`. Replace `em_task_queue mailbox` in `struct pthread` with a lightweight `em_thread_mailbox` intrusive FIFO linked via `em_task_queue::mailbox_next`: - Eliminates the remaining `malloc`/`free` on thread creation and shutdown, saving 1,536 bytes (wasm32) or 3,072 bytes (wasm64) of heap allocation per thread (plus allocator overhead) and making `_emscripten_thread_mailbox_init` infallible. - Shrinks `struct pthread` from 176 to 152 bytes on wasm32 (312 to 272 on wasm64) and drops the `em_task_queue_init`/`deinit` split and indirect notification wrapper functions.
sbc100
force-pushed
the
intrusive_pthread_mailbox
branch
from
December 2, 2026 16:39
eebdc3c to
ae96983
Compare
Member
|
I'd keep the |
tlively
reviewed
Dec 2, 2026
tlively
left a comment
Member
There was a problem hiding this comment.
Gemini nits:
Now that thread_mailbox.c no longer calls em_task_queue_enqueue, em_task_queue_enqueue, em_task_queue_dequeue, em_task_queue_is_empty, and em_task_queue_is_full are all internal to em_task_queue.c
and could be made static.
Comment on lines
-211
to
-212
| // Any subsequent messages to this queue (for example if a pthread struct is | ||
| // reused for a future thread, potentially on a different worker) will require |
Comment on lines
+83
to
+84
| pthread_mutex_destroy(&thread->mailbox.mutex); | ||
| thread->mailbox.notification = NOTIFICATION_NONE; |
Member
There was a problem hiding this comment.
Resetting this notification is now unnecessary, but harmless.
This branch has not been deployed
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.
Following #28449, each
em_task_queueonly ever carries one pending notification in its target thread's mailbox at a time (coalesced viaNOTIFICATION_PENDING) and already stays alive on the zombie list untilnotificationtransitions back toNOTIFICATION_NONE.Replace
em_task_queue mailboxinstruct pthreadwith a lightweightem_thread_mailboxintrusive FIFO linked viaem_task_queue::mailbox_next:malloc/freeon thread creation and shutdown, saving 1,536 bytes (wasm32) or 3,072 bytes (wasm64) of heap allocation per thread (plus allocator overhead) and making_emscripten_thread_mailbox_initinfallible.struct pthreadfrom 176 to 152 bytes on wasm32 (312 to 272 on wasm64) and drops theem_task_queue_init/deinitsplit and indirect notification wrapper functions.