Ajax takes 10x as long as it should/could

Yep, this is nasty issue that to have full WordPress environment you need to spend considerable time loading it.

I’ve needed much better performance (for very dynamic incremental search feature) for work and what I went with is:

  1. Custom file as Ajax handler.
  2. SHORTINIT constant for limited WP core load.
  3. Very selectively loaded parts of core, only those needed for the task.

This provides very limited environment, but performance is way way better and reasonable degree of compatibility with WP (starting with $wpdb) is retained.

Here is start my loader file, not pretty but works for specific needs:

<?php

ini_set('html_errors', 0);
define('SHORTINIT', true);

require '../../../../wp-load.php';
require( ABSPATH . WPINC . '/formatting.php' );
require( ABSPATH . WPINC . '/meta.php' );
require( ABSPATH . WPINC . '/post.php' );
wp_plugin_directory_constants();

// stuff goes here