DASPRiD / Dash

Flexible PSR-7 compliant HTTP router
BSD 2-Clause "Simplified" License
29 stars 9 forks source link

Optimization #26

Closed bakura10 closed 10 years ago

bakura10 commented 10 years ago

Here: https://github.com/DASPRiD/Dash/blob/master/src/Dash/Router/Http/RouteCollection/RouteCollection.php#L102

Implementing IteratorAggregate is much faster than implementing any iterator interface (because PHP needs to call around 5 custom functions at each iteration).

I'm wondering if you cannot implement IteratorAggregate, and do this in RouteCollection:

public function getIterator()
{
    if (!$this->sorted) {
        arsort($this->routes);
        $this->sorted = true;
    }

    return new ArrayIterator($this->routes);
}
DASPRiD commented 10 years ago

And how would the lazy instantiation work in that case?

bakura10 commented 10 years ago

You're right, my approach is wrong.

Other optimizations (didn't try them, you should test):

DASPRiD commented 10 years ago

Indeed, that would work.must be in the other order through to work:

$routeMatch->getParams() + $this->params

bakura10 commented 10 years ago

Ok so this should be a bit faster then :).

danizord commented 10 years ago

Good use case for generators :heart_eyes: ZF3 will be 5.4 or 5.5?

DASPRiD commented 10 years ago

5.4…

DASPRiD commented 10 years ago

Which reminds me, we are using the new merging now – can be closed.