protobuf-php/protobuf

Doing this in a pecl extension?

marksteele opened this issue · 1 comments

Hi boss,

Just curious. Have you ever considered just creating a pecl extension that reads .proto files then dynamically creates PHP objects from input protobuf data?

eg:

<?php
$Parser = new PBParser('/path/to/addressbook.proto');
$AddressBook = $Parser->parse($BinaryPayload);
...

My guess is that it would be several orders of magnitude faster. Just sayin'...

Hi boss !!
I actually have a prototype running something like this..

But I ended up giving up this approach,
The problem is that it require generating php classes and reading/writing messages dynamically.

So instead of doing it dynamically or generating metadata that describes the messages
The goal here is to generate messages that know exactly how to read/write themselves, so the reading and writing of messages became just simple/static php code.

I ran a couple benchmarks and saw in some cases 40% or 50% improvement over the metadata approach.

I believe that doing it dynamically would not make it any faster even as a pecl extension, especially on php7.

But I'm considering rewriting classes that deal with binary reading/writing as a optional extension.