# Variable fetch optimization

- Thread: https://externals.io/message/13098
- Original archive: https://news-web.php.net/php.internals/13098
- Started by Andi Gutmans on 2004-10-01T16:31:37+00:00
- Messages: 7
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #13098 — Andi Gutmans — 2004-10-01T16:31:37+00:00

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

Hi,

Attached is a patch to optimize variable fetches (basically it caches the 
fetches so that variables aren't re-fetched every time, most noticeable in 
loops with the loop control counter but also it's a general improvement).
It's similar to the patch Sterling and Thies did a year ago in their 
optimization patch.
As compiling the zend_execute.c file is starting to take a long time 
(minutes) due to inlining with the goto VM architecture, I suggest to apply 
Zend.m4 to make the default the function handler paradigm. The performance 
difference is not big and it'll make it easier to work on PHP. For 
production environments one can use a configure switch to turn this on.
I'd 
be happy to hear of benchmarks.

In general, there might be problems with extensions which access the active 
symbol table directly. It's something I still need to look into so please 
report any problems.

Please try and take some time to test it.

Andi

---

## #13099 — Andi Gutmans — 2004-10-01T16:39:13+00:00

URL: https://externals.io/message/13098#13099 · In reply to: #13098

http://snaps.php.net/~andi/Zend.m4.diff.gz
http://snaps.php.net/~andi/cv.diff.gz

At 09:31 AM 10/1/2004 -0700, Andi Gutmans wrote:
>Hi,
>
>Attached is a patch to optimize variable fetches (basically it caches the 
>fetches so that variables aren't re-fetched every time, most noticeable in 
>loops with the loop control counter but also it's a general improvement).
>It's similar to the patch Sterling and Thies did a year ago in their 
>optimization patch.
>As compiling the zend_execute.c file is starting to take a long time 
>(minutes) due to inlining with the goto VM architecture, I suggest to 
>apply Zend.m4 to make the default the function handler paradigm. The 
>performance difference is not big and it'll make it easier to work on PHP. 
>For production environments one can use a configure switch to turn this on.
>I'd be happy to hear of benchmarks.
>
>In general, there might be problems with extensions which access the 
>active symbol table directly. It's something I still need to look into so 
>please report any problems.
>
>Please try and take some time to test it.
>
>Andi

---

## #13109 — Thies C.Arntzen — 2004-10-02T10:44:36+00:00

URL: https://externals.io/message/13098#13109 · In reply to: #13098

before: 34.430
after: 20.126

do i need to say more?

(if it really works, which i haven't tested yet)

great andi!
re,
tc

PS: i really think that the vm should be generated by a script! looking 
at what makes most of the patch i really think that we're making 
hacking the engine more complex than needed.

On 2004-10-01 18:31:37 +0200, Andi Gutmans <andi@zend.com> said:

> 
> Hi,
> 
> Attached is a patch to optimize variable fetches (basically it caches 
> the fetches so that variables aren't re-fetched every time, most 
> noticeable in loops with the loop control counter but also it's a 
> general improvement).
> It's similar to the patch Sterling and Thies did a year ago in their 
> optimization patch.
> As compiling the zend_execute.c file is starting to take a long time 
> (minutes) due to inlining with the goto VM architecture, I suggest to 
> apply Zend.m4 to make the default the function handler paradigm. The 
> performance difference is not big and it'll make it easier to work on 
> PHP. For production environments one can use a configure switch to turn 
> this on.
> I'd be happy to hear of benchmarks.
> 
> In general, there might be problems with extensions which access the 
> active symbol table directly. It's something I still need to look into 
> so please report any problems.
> 
> Please try and take some time to test it.
> 
> Andi

---

## #13155 — Andi Gutmans — 2004-10-04T20:08:49+00:00

URL: https://externals.io/message/13098#13155 · In reply to: #13098

At 12:44 PM 10/2/2004 +0200, Thies C. Arntzen wrote:
>before: 34.430
>after: 20.126
>
>do i need to say more?
>
>(if it really works, which i haven't tested yet)

Made another fix (we had to take care of global variables being messed with 
by extensions).

>PS: i really think that the vm should be generated by a script! looking at 
>what makes most of the patch i really think that we're making hacking the 
>engine more complex than needed.

I am not sure. There are advantages and disadvantages to both.

pre-processor vs. script
Advantage: Only maintain source and not script (which might be icky), no 
pre-build scripts (which might be a PITA on platforms like Windows), no 
script portability issues
Disadvantages: More magic in the source code itself, might be slightly 
harder to debug.

Frankly, I am not sure what's better. I think it might be a good idea to 
see what can be done with a script and then compare. Will look into it.

Andi

---

## #13204 — Andrei Zmievski — 2004-10-06T20:36:38+00:00

URL: https://externals.io/message/13098#13204 · In reply to: #13109

> PS: i really think that the vm should be generated by a script! looking 
> at what makes most of the patch i really think that we're making 
> hacking the engine more complex than needed.

I agree..

- Andrei

---

## #13206 — Wez Furlong — 2004-10-06T22:10:20+00:00

URL: https://externals.io/message/13098#13206 · In reply to: #13204

I'm a big fan of making the computer do the work on our behalf (that's
what it's there for, right?).

It shouldn't be a huge problem to write a php script to generate the
different executors from a source file.  If you're worried about
bootstrapping, we can keep the generated files in CVS and/or bundle
them pre-generated in the distro.

--Wez.


On Wed, 6 Oct 2004 13:36:38 -0700, Andrei Zmievski
<andrei@gravitonic.com> wrote:
> 
> > […]
> 
> I agree..
> 
> - Andrei

---

## #13207 — Sterling Hughes — 2004-10-06T22:15:12+00:00

URL: https://externals.io/message/13098#13207 · In reply to: #13206

Wez Furlong wrote:

>I'm a big fan of making the computer do the work on our behalf (that's
>what it's there for, right?).
>
>It shouldn't be a huge problem to write a php script to generate the
>different executors from a source file.  If you're worried about
>bootstrapping, we can keep the generated files in CVS and/or bundle
>them pre-generated in the distro.
>  
>
Yeah, actually Dmitry wrote a script that converted the old executor 
into the new executor, so the script was already there.  I think its 
that Andi doesn't like the concept (I do like the concept btw), not the 
work involved.  Personally, I'd prefer to see the executor generated, so 
long as the source format is well thought-out.  Cause it will allow us 
to do things like, for example, generating an x86 JIT.

-Sterling
