# Single Stack for all generators

- Thread: https://externals.io/message/93241
- Original archive: https://news-web.php.net/php.internals/93241
- Started by Dmitry Stogov on 2016-05-11T14:54:19+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #93241 — Dmitry Stogov — 2016-05-11T14:54:19+00:00

URL: https://externals.io/message/93241#93241

Hi,


Nikita, please review the patch https://gist.github.com/dstogov/06116f1610f45f8152ine3a9927c6c243ac

It's the next attempt to use the single stack for all generators.

Now I don't see any problems or BC breaks.


In case "yield" is used as an expression in context of function call. e.g. var_dump(yield), engine backups and then restores active call frame chain.


Bob tested the patch on application that intensively uses generators, and reported:

15% less L2 cache loads

20% less cycle stalls due to memory subsystem

3% more  CPU_CLOCK_UNHALTED due to additional freeze/restore.


I'm going to commit this patch tomorrow.


Thanks. Dmitry.

---

## #93242 — Joe Watkins — 2016-05-11T15:02:49+00:00

URL: https://externals.io/message/93241#93242 · In reply to: #93241

404

Cheers
Joe



> Hi,
>
>
> Nikita, please review the patch
> https://gist.github.com/dstogov/06116f1610f45f8152ine3a9927c6c243ac
>
> It's the next attempt to use the single stack for all generators.
>
> Now I don't see any problems or BC breaks.
>
>
> In case "yield" is used as an expression in context of function call. e.g.
> var_dump(yield), engine backups and then restores active call frame chain.
>
>
> Bob tested the patch on application that intensively uses generators, and
> reported:
>
> 15% less L2 cache loads
>
> 20% less cycle stalls due to memory subsystem
>
> 3% more  CPU_CLOCK_UNHALTED due to additional freeze/restore.
>
>
> I'm going to commit this patch tomorrow.
>
>
> Thanks. Dmitry.

---

## #93243 — Bob Weinand — 2016-05-11T15:09:08+00:00

URL: https://externals.io/message/93241#93243 · In reply to: #93242

Looks like there is an "ine" in the link:

Correct link: https://gist.github.com/dstogov/06116f1610f45f81523a9927c6c243ac <https://gist.github.com/dstogov/06116f1610f45f81523a9927c6c243ac>

Bob

> Am 11.05.2016 um 17:02 schrieb Joe Watkins <pthreads@pthreads.org>:
> 
> 404
> 
> Cheers
> Joe
> 
> 
> 
> > […]

---

## #93246 — Nikita Popov — 2016-05-11T16:44:37+00:00

URL: https://externals.io/message/93241#93246 · In reply to: #93241

> Hi,
>
>
> Nikita, please review the patch
> https://gist.github.com/dstogov/06116f1610f45f8152ine3a9927c6c243ac
>
> It's the next attempt to use the single stack for all generators.
>
> Now I don't see any problems or BC breaks.
>
>
> In case "yield" is used as an expression in context of function call. e.g.
> var_dump(yield), engine backups and then restores active call frame chain.
>
>
> Bob tested the patch on application that intensively uses generators, and
> reported:
>
> 15% less L2 cache loads
>
> 20% less cycle stalls due to memory subsystem
>
> 3% more  CPU_CLOCK_UNHALTED due to additional freeze/restore.
>
>
> I'm going to commit this patch tomorrow.
>
The patch looks fine to me.

From my own testing with a "Hello World" Aerys server, after multiple
benchmark runs it previously started to mmap+munmap two new MM segments on
each request, leading to a decline from 50k rps to 5k. With the patch this
no longer occurs and the rps is stable at > 50k rps. (Though that may be
more luck than anything.)

Nikita
