News for hackers. Stuff that matters.
Re:Pux – High Performance Router for PHP by fooyc on Sunday January 12, 2014 @12:11PM (#7046534)
> Pux tries not to consume computation time to build all routes dynamically (like Symfony/Routing). Instead, Pux compiles your routes to plain PHP array for caching, the compiled routes can be loaded from cache very fast.

symfony/routing compiles routes only once to PHP code ([1]), and then that generated code is used for matching all subsequent requests. (There are multiple route matchers, but the default one works like this.)

It's amazing that Pux manages to be close to 50x times faster.

How is this achieved ?

[1] https://github.com/symfony/Routing/blob/0ee25e6580bd4169c128...

Re:Pux – High Performance Router for PHP by pedro93 on Monday January 13, 2014 @11:19AM (#7051413)
Explain here:

- Pux uses simpler data structure (indexed array) to store the patterns and flags. (In PHP internals, zend_hash_index_find is faster than zend_hash_find).

- When matching routes, symfony uses a lot of function calls for each route:

https://github.com/symfony/Routing/blob/master/Matcher/UrlMa...

- Pux fetches the pattern from an indexed-array:

https://github.com/c9s/Pux/blob/master/src/Pux/Mux.php#L189

- Pux separates static routes and dynamic routes automatically, Pux uses hash table to look up static routes without looping the whole route array.

- Pux\Mux is written in C extension, method calls are faster!

- With C extension, there is no class loading overhead.

- Pux compiles routes to plain PHP array, the compiled routes can be loaded very fast. you don't need to call functions to register your routes before using it.

Re:Pux – High Performance Router for PHP by fooyc on Monday January 13, 2014 @02:15PM (#7052658)
Thanks for your answer.

> When matching routes, symfony uses a lot of function calls for each route

This is the slow UrlMatcher. The one used by default in the standard symfony edition generates code like this: https://github.com/symfony/Routing/blob/0ee25e6580bd4169c128... , and this code is used for matching instead.

Re:Pux – High Performance Router for PHP by mjburgess on Sunday January 12, 2014 @12:39PM (#7046647)
Well for a start they're misusing apachebench gnuplot data (which isnt time-ordered).

And "compiled to php" is kinda meaningless, it depends what it's compiled to. There is no "native routing" language.

For my two cents, if you're having to translate your solution into simpler code your solution is wrong.

Re:Pux – High Performance Router for PHP by fooyc on Sunday January 12, 2014 @03:30PM (#7047330)
As always, it depends
Re:Pux – High Performance Router for PHP by Gigablah on Monday January 13, 2014 @02:53AM (#7049422)
> How is this achieved ?

By not utilizing the symfony/routing cache at all.

Sorry to say, this is a meaningless test.

Re:Pux – High Performance Router for PHP by cdekok on Sunday January 12, 2014 @01:03PM (#7046763)
Probably by the php extension in c :) I would think that phalcon router will be faster too.
Re:Pux – High Performance Router for PHP by fooyc on Sunday January 12, 2014 @03:29PM (#7047322)
The README says that the c extension is only 1.5x-2x faster than the pure PHP Pux. So this doesn't explain 50x faster.
Re:Pux – High Performance Router for PHP by pedro93 on Monday January 13, 2014 @01:02AM (#7049201)
1.5x-2x different is from apache.

the pure dispatching speed can be 10+x faster with C extension.