Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Customizing cont.new with stack size

Aperta
#156 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Attiva
Stack tecnologico
wasm
Ambito
compilers

Direzione di ricerca

Start by reviewing the cont.new instruction and the proposal's existing stack-switching semantics. Compare the listed stack-allocation strategies, then determine whether the small-coroutine marker, its minimum stack guarantee, and the well-defined overflow exception can be specified consistently. Done requires an agreed proposal-level design rather than a single localized edit.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

One of the trickiest issues to solve in stack switching is how big a stack to allocate for the new coroutine. Empirically, it has been observed that coroutines' memory requirements are often wildly divergent with some (perhaps most) coroutines only needing a small amount of memory to complete their task.

There are several ways of dealing with this:

  1. use fixed size stacks that are the same size as the default stack.
  2. implement a strategy for automatically growing stacks
  3. allow the user (toolchain) to specify the size of the stack for the new coroutine.

The advantages of these different approaches include:

  1. Simplicity of implementation.
  2. Sensitivity to actual computation requirements; in addition, the default size of a stack can be set to a small value -- allowing an application to have large numbers of suspended computations.
  3. The application author may be the best source of actual knowledge about the expected size of a task. Allowing the toolchain to express this facilitates this.

Each of these also has disadvantages:

  1. Particularly on limited memory platforms (such as mobile devices) there may not be enough address space to accommodate large numbers of large stacks.
  2. Automatically growing stacks is complex to realize (a stack overflow can occur in code that was not compiled for coroutining) and significantly increases the attack surface for security vulnerabilities.
  3. the toolchain may not know how much space to allocate for the stack. In particular, WebAssembly does not expose this information -- for good reasons. In addition, the toolchain may guess incorrectly.

A proposal:

allow a form of coarse grain estimation of the expected size of a coroutine, and throw a well defined exception when the actual computation is too large.

I suggest simply adding a marker to the cont.new instruction that declares that "the coroutine is small". This would allow the engine to allocate a small stack structure for that coroutine.

How small is small?

This may be implementation defined; however, I suggest that a more rigorous approach would be to specify a minimum amount of stack space would be available. This could be expressed in bytes but higher level, engine independent way, would be to state this as a combination of frames and local variables.

This approach would allow toolchains to optimize the overall memory footprint of generated applications whilst also allowing for some large stacks. One might imagine, for example, that when implementing generators most coroutines would be marked as small, whereas the default for green threads would be normal sized stacks.

Lingua principale
WebAssembly
Stelle
216
Fork
19
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di WebAssembly/stack-switching

Tutte le issue di WebAssembly/stack-switching

Issue simili

Altre issue su Compilers

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.