HNHacker News
TopNewBestAskShowJobs

pedro93

232 karma · joined March 27, 2013

submissionscomments
pedro93··on Xarray – The missing PHP array functions, implemented in extension
Fixed memory leaks and it might be the time to release :p
pedro93··on Show HN: Funk – a toolkit for using PHPSGI stack (middleware, http servers)
Funk implements PHPSGI specification (the PHPSGI repository contains middleware/app interfaces implemented in both PHP and Zend Extension)

https://github.com/phpsgi/phpsgi

pedro93··on A Git GUI Tool: FactCommit Pre-Release
there is a typo, it's FastCommit. :p
pedro93··on CLIFramework: Building powerful command-line application in PHP
http://imgur.com/Db5obT8 powerful zsh completion generator
pedro93··on R3 bindings for Node.js
the routes are pre-compiled, so I think it only requires one calling conversion from js to c++ when dispatching routes.
pedro93··on R3 bindings for Node.js
It's a binding library of r3, you may check the benchmark from r3 project:

https://github.com/c9s/r3#performance

pedro93··on R3 – High-performance URL router library in C
well. implementing these feature testing scripts is kinda waste of time. so I rather to pick up autotools, which provides a integrated features.

to use it for a static embedded use case, you may write your own build script to compile the library (it's not hard to write one). the cflags are describe in src/Makefile.am

and you can use pkg-config to list the flags you need.

pedro93··on R3 – High-performance URL router library in C
When you use pcre in python or ruby, do you worry about the complexity? pcre and language VMs are also implemented in C/C++.

If we consider complexity before everything, we must use PHP to implement an OS. :-p

pedro93··on R3 – High-performance URL router library in C
Thanks! that helps!
pedro93··on R3 – High-performance URL router library in C
Hi! your implementation is inspiring to me. so I mixed some other ideas to implement this (for fun and experimentation).

this router library can be used for different purpose (outside of URL dispatching), although we don't gain so much performance from the point of view of each single request.

pedro93··on R3 – High-performance URL router library in C
The behavior of (strndiff / strdiff) is different from strncmp or strcmp. strn?cmp does not return the offset. they are different functions.

and in order to ship this package to deb, deploy to different platform, use autotools to test C features is a requirement. (we used to build the project with cmake before we use autotools)

pedro93··on R3 – High-performance URL router library in C
well, just for fun!
pedro93··on Impact Resistant Screen Protector
It's really amazing, how does it work?
pedro93··on Pux – High Performance Router for PHP
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.

pedro93··on Pux – High Performance Router for PHP
well, flight is not written in C extension.

have checked the code, there are a lot of magic method calls in flightphp. magic method calls are even slower than normal method call.

pedro93··on Pux – High Performance Router for PHP
Yes you can use APC, opcache or XCache to load php bytecode in runtime. but you are still calling php functions/methods or creating a lot of objects in runtime. that's the overhead.
pedro93··on Pux – High Performance Router for PHP
1.5x-2x different is from apache.

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

pedro93··on Pux – High Performance Router for PHP
I don't think so.

Using pure PHP, you need to load a lot of class files. and function calls, method calls, hash find are pretty slow in pure PHP.

- First of all, while using C extension, you don't need to reload these php class files again and again. it reduces the class loading overhead.

- Seconds, looping and string comparison is pretty fast in C. it's because in pure PHP, it duplicates the string when calling functions/methods in the runtime.

- Third, there are a lot of spaces to optimize the code in C rather than in pure php.

- Last, pure PHP consumes a lot of memory, but in C extension, the memory footprint is pretty small.

pedro93··on Pux – High Performance Router for PHP
Yes, you can do routing without compiled routes.
pedro93··on Pux – High Performance Router for PHP
First of all, for your information, the benchmark code and details are already there: https://github.com/c9s/router-benchmark sorry I forgot to put the link. :p

We firstly tested the pure dispatching benchmark by a simple benchmark tool. (without ab), code is here.

https://github.com/c9s/router-benchmark/blob/master/code/dis...

Tests including klein, ham, aura, symfony/routing. This tests pure dispatching speed, so the benchmark does not includes cache.

The dispatching benchmark result is here:

https://github.com/c9s/router-benchmark/blob/master/code/dis...

The benchmark with apache is just to show the comparison result (which shares the same configurations).

Pux is basically written in C extension, which reduces the overhead to load classes from PHP files. Also it does a different strategy on route dispatching. to compare the routes as fast as possible, pux uses indexed array to store the route pattern, pcre flag. (In PHP internals, zend_hash_index_find is faster than zend_hash_find)

it's not just iterating all routes in a big loop like Symfony.