Skip to content

Instantly share code, notes, and snippets.

View felixarntz's full-sized avatar

Felix Arntz felixarntz

View GitHub Profile
@felixarntz
felixarntz / wp-server-timing-quick-hack-template.php
Created March 8, 2024 01:06
wp-server-timing-quick-hack-template.php (using Performance Lab Server-Timing API)
<?php
function my_func() {
global $some_metric_global;
if ( ! isset( $some_metric_global ) ) {
$some_metric_global = 0.0;
add_action(
'wp_footer',
function() {
@felixarntz
felixarntz / wp-total-compared-with-ttfb.sql
Created October 26, 2023 23:36
HTTP Archive query comparing Server-Timing `wp-total` (from Performance Lab plugin) with Time to First Byte
CREATE TEMPORARY FUNCTION GET_SERVER_TIMING_HEADER(headers ARRAY<STRUCT<name STRING, value STRING>>) RETURNS STRING AS (
IFNULL((
SELECT
value
FROM
UNNEST(headers) AS header
WHERE
LOWER(header.name) = 'server-timing'
LIMIT 1
), '')
@felixarntz
felixarntz / wp-64-beta1-benchmarks.md
Created October 3, 2023 00:13
Local results from running https://github.com/swissspidy/compare-wp-performance for WordPress 6.4 Beta 1

WP 6.4 Beta 1 Benchmarks

Compared to WP 6.3.1 via https://github.com/swissspidy/compare-wp-performance, based on running:

./run.sh latest https://wordpress.org/wordpress-6.4-beta1.zip

Overview

| Metric | Run 1 Before | Run 1 After | Run 1 Diff % | Run 1 Diff abs. | Run 2 Before | Run 2 After | Run 2 Diff % | Run 2 Diff abs. |

@felixarntz
felixarntz / prevent-jetpack-subscriptions-thickbox.php
Created September 27, 2023 04:08
Jetpack uselessly enqueues Thickbox JS (which itself enqueues jQuery!) when rendering the Subscriptions block, even though it doesn't even use Thickbox. I use this snippet on my own site to fix it.
<?php
/**
* Fix Jetpack Subscriptions block to not uselessly enqueue Thickbox, which in turn enqueues jQuery.
*/
function felixarntz_stop_jetpack_subscriptions_from_enqueuing_thickbox_without_any_usage() {
if ( wp_script_is( 'jetpack-block-subscriptions' ) && isset( wp_scripts()->registered['jetpack-block-subscriptions'] ) ) {
$script = wp_scripts()->registered['jetpack-block-subscriptions'];
$index = array_search( 'thickbox', $script->deps, true );
if ( false !== $index ) {
@felixarntz
felixarntz / server-timing-output-buffer.php
Last active March 10, 2023 21:22
Mini WordPress plugin that enables output buffering in the Server Timing API of the Performance Lab plugin (also see https://github.com/WordPress/performance/pull/553) to unlock a few additional metrics
<?php
/**
* Plugin Name: Server Timing Output Buffer
* Plugin URI: https://gist.github.com/felixarntz/9c3d7150c74082e69bb426393b68b12e
* Description: Enables output buffering in the Performance Lab plugin's Server Timing API.
* Requires at least: 6.1
* Requires PHP: 5.6
* Version: 0.1.0
* Author: Felix Arntz
* Author URI: https://felix-arntz.me
@felixarntz
felixarntz / theme.json
Created March 4, 2023 19:55
My Twenty Twenty-Three child theme's `theme.json` for https://felix-arntz.me
{
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 2,
"settings": {
"color": {
"palette": [
{
"color": "#ffffff",
"name": "Base",
"slug": "base"
@felixarntz
felixarntz / web-vitals-logger.php
Last active February 16, 2023 22:55
Mini WordPress plugin that uses https://github.com/GoogleChrome/web-vitals to log Core Web Vitals and other key client metrics to the browser console
<?php
/**
* Plugin Name: Web Vitals Logger
* Plugin URI: https://gist.github.com/felixarntz/112c5dcb72ca3af86557550979a5e9dd
* Description: Logs Core Web Vitals and other useful client-side metrics in the browser console.
* Requires at least: 6.1
* Requires PHP: 5.6
* Version: 0.1.0
* Author: Felix Arntz
* Author URI: https://felix-arntz.me
@felixarntz
felixarntz / server-timing-extra.php
Last active August 9, 2023 05:23
Mini WordPress plugin that uses the Server Timing API of the Performance Lab plugin (also see https://github.com/WordPress/performance/pull/553) to capture additional metrics
<?php
/**
* Plugin Name: Server Timing Extra
* Plugin URI: https://gist.github.com/felixarntz/63c05392dbf7d51cc7f8f4a424b1ff39
* Description: Exposes additional Server-Timing metrics using the Performance Lab plugin's Server Timing API.
* Requires at least: 6.1
* Requires PHP: 5.6
* Version: 0.1.0
* Author: Felix Arntz
* Author URI: https://felix-arntz.me
@felixarntz
felixarntz / README.md
Last active February 23, 2024 11:04
Mini WordPress core server performance test suite

Mini WordPress core server performance test suite

Purpose

This quick "mini test suite" allows you to easily collect server-side performance metrics for WordPress core development. It does so by utilizing the Server-Timing header.

Usage

  1. Paste the code from main.php into pretty much anywhere in WordPress core, e.g. into wp-includes/default-filters.php.
  2. Use code like the one in example.com around any code or a specific function that you want to record metrics for.
@felixarntz
felixarntz / perflab-server-timing-examples.php
Last active November 24, 2022 00:29
Some example use-cases for the Server Timing API in the Performance Lab plugin (see https://github.com/WordPress/performance/pull/553). A previous version for an older implementation of the API can be found at https://gist.github.com/felixarntz/c343a33242b6527ad3f446c8f7f4fec2.
<?php
add_action(
'plugins_loaded',
function() {
// Utility function that returns a measuring callback for an action hook,
// which should be registered as a metric within the action as early as possible
// (see PHP_INT_MIN usage below).
$get_measure_action_callback = function( $action_hook ) {
return function( $metric ) use ( $action_hook ) {
$metric->measure_before();