memorysafety / memorysafety/rav1d
Restore thread stack size setting
Nobody has claimed this yet.
- Dominant language
- Assembly
- Stars
- 643
- Forks
- 81
- PR merge metrics
- No merged PRs in 30d
Description
dav1d sets the stack size of new worker threads, and initially rav1d did, too. But in order to switch to thread::spawn from the unsafe pthread_create, the creation of Rav1dTaskContexts was moved from a Box<[_]> on the main thread's heap to on the stack in each worker thread. This was done to satisfy the borrow checker and ensure the Rav1dTaskContext's lifetime lasted as long as the thread, which aren't scoped. However, Rav1dTaskContext is huge (258,624 bytes), which is larger than a thread's min stack size, which dav1d sometimes set. Moving it to the heap with Box::new doesn't work since Box::new still takes it as an argument on the stack, and the way to directly create it on the heap through Box::new_uninit or Box::new_zeroed is unstable. Low-level alloc APIs could be used directly as well, but they're not ideal either. But since Rust uses a default stack size of 2 MB usually, there's more than enough stack space for Rav1dTaskContext if we don't set it lower. Thus, that's what we'll do for now (in #887). If memory usage of thread stacks proves to be an issue, we can restore the previous/dav1d behavior, perhaps by setting at least mem::size_of::<Rav1dTaskContext>() of stack size, which would be a net equal in memory usage overall.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Trace the worker-thread creation and the construction of Rav1dTaskContext, paying attention to the move from pthread_create to thread::spawn and the decision described alongside #887. Determine how the former dav1d stack-size behavior can be restored without putting this large context on the stack; done means worker stacks accommodate Rav1dTaskContext while preserving thread lifetime and memory goals.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- performance
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100