Hi,
If you're even interested in the tinyest of optimizations, you may wanna
read this. I was just going through the php code. I'm not familiar with it
at all, so I don't know which functions are the bottlenecks, so I can't help
in optimizing the big picture. But I had little else to do right now, so I
figured I'd just browse around through the files to see if I could notice
any local speedups. So really, the things I lay out here are probably
futile, but who knows.
-----
I found that for example the function php_stream_memory_seek() in
main/streams/memory.c contains a whole bunch of return statements. I found
that it can be (you can benchmark this) slightly faster to do this:
int func(int p)
{
int result = 0;
switch (p)
{
case 0: result = 1; break;
case 1: result = -4; break;
case 2: result = 15; break;
}
return result;
}
instead of this:
int func(int p)
{
switch (p)
{
case 0: return 1;
case 1: return -4;
case 2: return 15;
}
return 0;
}
This is correct with 'gcc foo.c' as well as with 'gcc -O2 foo.c'. The
difference is slight, and if it's too tiny, just ignore it this message.
Perhaps some functions that php relies on heavily may benefit from this
though (but I wouldn't know which ones those would be).
-----
Also, I noticed that in php_start_ob_buffer() in main/output.c, and probably
in more functions integers are divided by 2 by doing:
result = intvar / 2;
while it is about 20% faster (even with -O2) to do this:
result = intvar >> 1;
-----
A minor thing I noticed (nothing to speed up here though) is an unused
variable 'i' in insertionsort() in main/mergesort.c (weird that this never
showed up as a compiler warning). Or does the defined TSRMLS_CC depend on
the existance of an integer called 'i'? Pretty unlikely to me.
-----
Why is CONTEXT_TYPE_IMAGE_GIF in main/logos.h defined as "Content-Type:
image/gif" with 2 spaces between "Content-Type" and "image/gif"?
-----
In sapi/apache/mod_php5.c in the function php_apache_log_message(),
Why are these 2 calls:
fprintf(stderr, "%s", message);
fprintf(stderr, "\n");
instead of 1 call:
fprintf(stderr, "%s\n", message);
-----
In sapi/apache/mod_php5.c in the function php_apache_flag_handler_ex(),
the original:
if (!strcasecmp(arg2, "On") || (arg2[0] == '1' && arg2[1] == '\0')) {
bool_val[0] = '1';
} else {
bool_val[0] = '0';
}
is over 5 times slower than:
if (((arg2[0] == 'O' || arg2[0] == 'o') && (arg2[1] == 'n' || arg2[1] ==
'N') && (arg2[2] == '\0')) || (arg2[0] == '1' && arg2[1] == '\0')) {
bool_val[0] = '1';
} else {
bool_val[0] = '0';
}
-----
Like I said, these are extremely tiny things, so please ignore it if it's
too futile

Nonetheless, if this turns out to be appreciated information,
I'll continue the hunt.
Good luck optimizing,
Ron
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php