Performance Benchmarking
Performance Benchmarking
To ensure that contributions to this repository maintain high standards for speed and efficiency, we provide a set of tools and methodologies for measuring the impact of code changes on database performance and page load times.
Recommended Tools
We recommend the following stack for local performance validation:
- Query Monitor: The primary tool for identifying slow database queries, hooks, and HTTP requests.
- WP-CLI Profile Command: Used for measuring the execution time of internal WordPress processes from the command line.
- Xdebug (Profiling Mode): For deep-dive analysis of function call stacks and bottleneck identification.
Measuring Query Performance
When introducing new custom post types, taxonomies, or complex meta queries, use the built-in WordPress benchmarking functions to capture baseline versus optimized metrics.
Usage: Simple Execution Timer
You can wrap your logic in the standard WordPress timer functions to measure the duration of a specific operation.
// Start the timer
timer_start();
// Logic to benchmark (e.g., a complex WP_Query)
$results = new WP_Query([
'post_type' => 'contribution',
'posts_per_page' => 50,
'meta_key' => '_performance_score',
'orderby' => 'meta_value_num'
]);
// Capture the result
$elapsed_time = timer_stop(0, 4);
error_log("Query execution took: " . $elapsed_time . " seconds.");
Benchmarking Metrics
Focus on these key performance indicators (KPIs) when submitting optimizations:
| Metric | Target | Description | | :--- | :--- | :--- | | Total Queries | < 30 per page | The total number of SQL queries required to render the view. | | Slow Queries | 0 | Any query taking longer than 0.05s is considered a candidate for indexing or caching. | | Memory Usage | < 32MB | Peak PHP memory usage for a standard request. | | TTFB | < 200ms | Time to First Byte (measured in a local, non-cached environment). |
Benchmarking via WP-CLI
For a headless performance check, use the eval command to profile specific repository functions without browser overhead.
# Measure the time taken to execute a specific repository function
wp eval 'timer_start(); \
UditAkhourii\WP\Optimizations::process_weekly_contributions(); \
echo "Process Time: " . timer_stop(0, 4) . "s\n";'
Database Impact Analysis
If a contribution modifies the database schema or adds high-volume wp_options entries, use the following snippet to monitor the query count increase:
global $wpdb;
$initial_queries = $wpdb->num_queries;
// Execute component logic
do_action('ua_wp_weekly_contribution_init');
$final_count = $wpdb->num_queries - $initial_queries;
echo "Logic executed {$final_count} additional database queries.";
Production Monitoring (Internal Only)
[!NOTE] While the repository includes hooks for external monitoring (such as New Relic or Datadog), these are handled internally by our infrastructure layer. Users should focus on local
Query Monitoroutput for standard contributions.