[wp-hackers] Re: Streamlining Includes

Jacob Santos wordpress at santosj.name
Mon Mar 3 06:10:07 GMT 2008

>> I'd love to streamline includes for 2.6.  Thoughts?
> Ryan, I think this is a much needed and worthwhile change.

I disagree, on the grounds that the proposed API will increase overhead,
not decrease it and will over complicate includes.


if( is_admin() )
   require_once( ABSPATH . 'wp-admin/includes/some_file.php' );

1. Compiler compiles branch
2. Compiler skips over require_once()
3. PHP Executor parses over branch, checks to see that it evaluates to true
4. Runs require_once()
5. File is passed to PHP Compiler.

Now take APC for instance. APC can not cache some_file.php until #5. In
which case, the file would have already been cached if the branch was not



wp_include_file('some_file.php', WP_INCLUDES_ADMIN);


function wp_include_file($file, $dir = '')
    if( file_exists( ABSPATH . slashit($dir) . $file ) )
        include_once(ABSPATH . slashit($dir) . $file);

    else {
        if( 'edit_posts' == $file )
            require_once( ABSPATH . 'wp-admin/includes/posts.php' );
        else if( ... )
            require_once( ABSPATH . ... );

Lets say for a moment that it takes 0.001 seconds overhead to run the
function line. So each call to wp_includes_file() has 0.0001 + the time it
takes execute the function.

So if you have 100 function calls, it automatically takes 0.01 seconds to
even start up the function call. If you have a 1000 function calls, that
is 0.01 seconds. That doesn't count the best case when the file exists. If
the capability type system is used for convenience, then each branch will
have to be executed until the correct one is found.

If you have 10 branches, then the best case would be the first would be
picked, but that is not likely to be the case. Just imagine the overhead
if you had a 100 branches or use a database!

This system also totally circumvents opcode caches like APC.

Jacob Santos

http://www.santosj.name - Personal Blog
http://funcdoc.wordpress.com - WordPress Function Documentation Blog

More information about the wp-hackers mailing list