# SPL and foreach Optimized

- Thread: https://externals.io/message/1974
- Original archive: https://news-web.php.net/php.internals/1974
- Started by marcus.boerger@t-online.de on 2003-05-25T02:12:01+00:00
- Messages: 1
- 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

---

## #1974 — marcus.boerger@t-online.de — 2003-05-25T02:12:01+00:00

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

Hi all,

during saturday i've spent some time to optimize SPL. For my testcase it is 
now 3% faster then
the compareable while code. If OPTIMIZED_ARRAY_CONSTRUCT is defined as in 
current CVS
then the difference is about 3.5%. Looking at the profiling results on that 
.5% difference i was
directed to the emalloc change posted earlier. This will bring some more % 
(hopefully >5%).

SPL uses op1->u.EA.type as an info pointer (called spl_foreach_proxy) to 
keep track of its
current index and cache the . This can also be used for normal foreach and 
make the
array copying there obsolete, which also allows some more "code tricks" (as 
already requested/
bugged on bugs.php.net).

Integrating SPL in the engine would also nearly completly drop the 
performance loss of the hooks
which is less then 0.5% atm (foreach, array not measured yet).

The optimization used with OPTIMIZED_ARRAY_CONSTRUCT could also be used for 
normal
foreach.

regards
marcus


-- 
------------------->>> mailto:mail@marcus-boerger.de <<<------------------
"We are animals among animals, all children of matter,
save that we are the more disarmed. But since, unlike animals,
we know that we must die, let us prepare for that moment
by enjoying the life that has been given us by chance and for chance."
                                Umberto Eco, The island of the day before
--------------------->>> http://marcus-boerger.de <<<
