生成器函数的局部变量是存储在栈上还是堆上?
Are generator function's local variable stored on Stack or Heap?
在这篇文章中:
https://wingolog.org/archives/2013/06/11/ecmascript-generators-from-a-performance-perspective,它提到:
In a generator function, V8 stores local variables on the heap
instead of on the stack.
但它也与下一段自相矛盾:
The exception to this case is when you yield and there are
temporaries on the stack. Recall in my article on V8's baseline
compiler that the full-codegen is a stack machine. It allocates slots
to named locals, but temporary values go on the stack at run-time,
我不明白的部分是生成器函数总是使用yield,我假设文章中提到的suspension指的是yield 声明。
我认为这篇文章缺少示例:
return 12 + yield 5
在这种情况下,12 必须分配在堆栈上,并且在挂起迭代器时,必须将其复制出堆栈,然后在迭代器继续时再次进入堆栈。第二段讲的是"temporaries"(这里是12),不是"variables".
在这篇文章中: https://wingolog.org/archives/2013/06/11/ecmascript-generators-from-a-performance-perspective,它提到:
In a generator function, V8 stores local variables on the heap instead of on the stack.
但它也与下一段自相矛盾:
The exception to this case is when you yield and there are temporaries on the stack. Recall in my article on V8's baseline compiler that the full-codegen is a stack machine. It allocates slots to named locals, but temporary values go on the stack at run-time,
我不明白的部分是生成器函数总是使用yield,我假设文章中提到的suspension指的是yield 声明。
我认为这篇文章缺少示例:
return 12 + yield 5
在这种情况下,12 必须分配在堆栈上,并且在挂起迭代器时,必须将其复制出堆栈,然后在迭代器继续时再次进入堆栈。第二段讲的是"temporaries"(这里是12),不是"variables".