[wp-hackers] Streamlining Includes
Aaron Harun
admin at anthologyoi.com
Mon Mar 3 02:18:14 GMT 2008
The major problem I see is that for blogs with a lot of plugins,
everything would be defined anyway because all activated plugins would
still be loaded by default, so the only time this would have any real
benefit is when just code that is rarely used by the core as well as
plugins is removed.
For example, one of my plugins sends an AJAX request to the server to
return the content of a post. The file the request is sent to has to
include the WordPress core -- including all of the plugins, so that
the content of the post is correctly formatted and then sent back.
Under the current system, even small requests have to include
everything to send back a small amount of correctly formatted data. It
isn't pretty, but even including the entirety of WP is smaller than
the amount of work needed to load an entire page. This same process
occurs no matter what else (comments, pages, etc) is requested from
WP.
Even if each plugin only included what it needed, the entirety of the
core would be included because on or another plugin would have needed
it regardless of whether the plugin is actually useful. (For example,
an Admin panel add-on is included no matter what page you are on.)
There needs to be a better way to define what is happening in general
so that WordPress can specifically, and intelligently, select what
plugins and includes are included.
Part of optimizing the core may require that plugins "announce" what
they do, so WordPress knows how to respond: when plugins are
activated, they should define their functionality to WordPress. This
could be as simple as adding a list of functionality in the header of
each file that WordPress can store as part of the plugin data.
That AJAX plugin might have "Functions: posts, comments" while the
Simple Tags plugin might use "Functions: tagging, admin."
This way, WordPress would know that if it was in the admin panel, but
it wasn't on a page related to tagging, Simple Tags wouldn't need to
be loaded, but if it was editing a post or listing categories, it
would, and even if some later plugin defined that it was going to need
tagging functionality, Simple Tags could be included then.
Similarly, for the AJAX plugin, it could define a variable -- or
whatever -- before including wp-config, so that WordPress could "know"
what functions and plugin categories were needed. Normally, doing this
would include the entire core, but if the AJAx plugin was just loading
a post, it would define the variable as such, and WordPress would
_start_ by loading only plugins and functions part of the "post"
group. If other plugins needed more functions, WordPress could spider
out from there to include what it needs.
This ended up longer than what I wanted, so I hope I stayed sem-coherent.
Aaron.
More information about the wp-hackers
mailing list