typelevel / typelevel/cats-effect
Consolidate `IOFiber`'s `objectState` and `conts` stacks on Native
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 2.2k
- Forks
- 576
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 18
Description
This should enable a few wins:
-
Reduce
IOFiber's memory footprint. We would now only need a pointer to one stack, not two. -
Elide allocations and a pointer chase. Currently we have a pointer to
ArrayStack, which itself has a pointer to anArray. Now we would store the stack size as the first element of the array and thus remove the intermediate allocation. -
(Pointers to) objects and conts would be interleaved in a contiguous array e.g. in the following code, the popped cont and the popped pointer to the lambda would be consecutive in memory. This is a much more favorable access pattern.
One possible caveat is that the memory footprint of the stack itself will increase since the cont bytes can no longer be packed when interspersed with object pointers due to alignment requirements.
Making this change will require support from Scala Native to allocate memory that can be accessed unsafely as a Ptr[Byte] but is conservatively traced by the GC. I will shortly open an issue upstream about that and link it here (update: https://github.com/scala-native/scala-native/issues/3312).
Another issue is whether we can implement this change with the usual Platform techniques, or if it would require us to duplicate IOFiber for Native 😕
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
Start with the referenced IOFiber.scala code around lines 1164-1166 and review the linked Scala Native issue about conservatively traced unsafe memory. Determine whether the two Native stacks can be consolidated without duplicating IOFiber or violating the alignment and tracing constraints. Done means the Native implementation uses one interleaved stack with the stated memory and allocation benefits.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100