> The idea behind PHP from day one was that it was an environment for
> wrapping compiled code. Things that are performance critical is written
> in C/C++ and things that aren't are left in the PHP templates. Whether
> you issue an SQL query from PHP or from a compiled C program doesn't
> affect the overall performance of the system so you might as well do
> that from PHP.
>
> If you are calculating a fractal, you write it in C and expose it to PHP
> with a get_fractal($args) function call so you can mark it up and easily
> change the args passed to the underlying function.
Ah yes, thank you (the people who built the system in PHP) for that, it
is very easy to use.
Well, more to the point, I don't think this should be a requirement. It
is possible to call PHP functions from within machine code, so more to
the point, why not build functions in PHP language and keep them as
machine code for each machine? The technology is there to where you
won't even have to interpret the source until you see it has been
modified and can do the conversion over again.
Not everyone knows C/C++, not everyone cares to know C/C++, not everyone
should need to know C/C++. That requirement for speed intensive code
bothered me and still does. Yes, thank you there are other languages,
but I'll rather learn PHP until I reach advanced level and I'm not there
yet. Should always learn one language really well before going on to
"greener" pastures.
The second reason is that it is harder to get someone to compile your
extension and include it than it is to get someone to use your PHP
language library or script. What you stated is what ADOdb does, but I
would suspect that not many that use it have the extension also. That is
the point, I shouldn't have to write C, unless the feature doesn't
exist. If I have to write C for PHP functions, then what is the point?
PHP does do a really great job of making it extremely easy to write
extensions or as much as is possible. You still have to worry about
whether or not the user is able to add the extension, the user knows
enough to install it, or would take the time to do so.
I do remember reading something that JIT compiling can be better than
regular compilation since it can do the sensing you described.
> It is really important for PHP to have as little overhead as possible
> between itself and the speed-critical code behind it and less important
> that the userspace executor is fast. That doesn't mean it should be
> slow. It should be as fast as we can make it, but not at the cost of
> convenience.
Yes, I'm saying the userspace executor can be quicker using JIT
compilation. Well, to be completely accurate, there would be a little
tiny, you'll-barely-notice-it-is-there delay during the JIT stage. It
should be manageable.
>
> What APC does is to eliminate the continual recompilation to bytecode.
>
Bytecode cache? That is interesting, I understand how APC is used, I
just don't know the implementation. It is nice that APC uses bytecode
instead of PHP opcodes as it might be a little bit quicker.
Why not go a step further and compile to machine code? I like the idea
of using opcode to transfer from machine to machine (such as in Java),
but it was always confusing why PHP's standard package never just saved
the opcode. Sure there are compilers (some don't work well, others you
have to pay for), but the technology already exists in PHP.
The idea of using JIT compiling is really to do away with continuing
interpreting, compiling, and running to slice it down and save the
machine code for later reading. You can cut that all down to just one
stage. PHP runs compiled code on top of itself and does the whole
interpreting stage if it needs to.
>
> It would make PHP more complicated to distribute since a translator to
> CPU specific machine could would be needed.
>
That would be where Lightning library would come in. I would suspect
that the library would be able to sense the CPU architecture at compile
time.
>
> Before thinking about this: try to demonstrate how much we would gain
> on typical web sites.
>
Ah yes, the million dollar question. How much would be benefited from
JIT compiling? Would there be a benefit? Currently with the commercial
PHP compiler, there is an overall increase of milliseconds (not much if
you think of it). The only way to answer this is doing it and giving the
results. Give me a year or two, I just didn't want to start it if
someone else was doing it.
The discussion with my teacher was that when you have an algorithm that
uses an loop in an interpreted language it will always be faster to have
that in machine code (eh, you could argue that a poor assembler
algorithm would be slower than a better written C algorithm). There, I
would assume, is overhead in the PHP engine where you have to run the
code, reading it, running the compiled routine. If it was machine code
PHP would not be required to read the Opcode and would remove that
overhead from the process.
How much would you save? A few milliseconds at least. When you have a
horrible loop intensive algorithm, you would be able to tell the
difference as my teacher was. I think it is pretty... well, I'll rather
would like to stay away from C web programming thank you.
Most Web sites only take a few milliseconds to process anyway and most
overhead is from SQL transactions. Still, I contend that JIT compiling
would still be worth looking at.
Really, what I would think the biggest overhead is at is (even with APC)
interpreting and compiling the source. It is possible to save the
machine code for later use for shared hosting. For the idea of using
APC, I kind of like it and will take a look at the source to see if it
is possible for me.
JIT doesn't have to be a function at a time, it can be whole classes,
files, or the entire script.
The symbol table would map better to assembler, I mean machine code
since basically you are working with stacks anyway. The PHP symbol table
in C is just easier to write and maintain. That probably would have to
be compiled at run time.
Personally, I would like to do without the whole interpreting of the
source and have PHP as a completely compiled (as in bytecode) language.
I suspect that would not go off to well, so therefore I propose
something that is compatible with what PHP does now. Should also be
easier as everything I would need to do already exists.
Jacob Santos