Snippet performance Pro
Pro · This feature is part of Snipfire Pro. Plans
Snipfire itself adds almost nothing to a page (see Does it slow my site down?). Your snippets are another matter: a query in a loop or a slow API call can cost more than you think. Snippet performance measures what each snippet costs, so you can find the slow ones.
It's off by default, and while it's off it adds no work to any page.
Switch it on
Go to Snipfire → Tools & Safe Mode → Snippet performance and choose under Measure snippet performance:
| Setting | What's measured |
|---|---|
| Off (no extra work on any page) | Nothing. The default |
| On for admins' own page views | Only the pages you (and other administrators) view. Visitors are never measured |
| On for a sample of all visitors | 1 in N requests of all visitors (Sample: measure 1 in … requests, default 100), plus admins' page views |
Flag a snippet as slow from an average of … ms per page sets when a snippet counts as slow (default 50 ms). Click Save.
Start with admins' own page views: browse the pages that matter (the home page, a product, the checkout), then look at the figures. Use a sample to see real visitors' pages, such as logged-in customers or search results you'd never open yourself.
What's measured
For each snippet, the time and memory it costs on a page:
- a PHP snippet's code, and the callbacks it hooks into WordPress with
add_action()andadd_filter(), timed when they actually run, not when they're added, - rendering and printing an HTML snippet or a shortcode,
- adding a CSS or JavaScript snippet to the page.
A snippet's own time is counted; a snippet it runs in turn (a shortcode inside its output, for example) counts for itself. Page addresses are stored without their query strings.
Where to see the figures
- The admin bar, on the front end: Snipfire: 12 snippets · 3.4 ms, the snippets on this page and their time. Open it for the list; a slow snippet is shown in red. Click one to open it in the editor.
- The editor's snippet list: a time badge next to each measured snippet, red when it's slow.
- Performance at the bottom of a snippet's settings: Average, 95th percentile (95 of 100 page views are faster), Slowest (and on which page), Memory, how many page views were Measured, and when it was Last seen. Slow: this snippet takes … per page on average. when it's over your threshold.
- WP-CLI:
wp snipfire profilelists every snippet's figures.
The figures use each snippet's last 1,000 measurements from the last week.
How much it costs
Measuring adds some work to the pages it measures, growing with the number of snippets: in our benchmark, about 25 ms per admin page with 1,000 snippets and about 95 ms with 3,000. Pages that aren't measured (visitors outside the sample, or everyone while it's off) cost nothing extra. Switch it off again when you've found what you were looking for.
Where the measurements are kept
In files next to your snippets (wp-content/snipfire/profile/), one per day, for a week, and at most 2 MB a day. Nothing is sent anywhere and nothing is written to the database on page views.
Delete the measurements on the Tools page (or wp snipfire profile --reset) starts afresh, for example after fixing a slow snippet.
Who can use it
- Changing the settings and deleting the measurements: full Snipfire access.
- The figures in the editor: everyone with Snipfire access, including View only.
- The admin bar item: administrators.
From the command line
wp snipfire profile --mode=admins # measure admins' own page views
wp snipfire profile --mode=sample --rate=50 # 1 in 50 requests, plus admins
wp snipfire profile # the figures, slowest average first
wp snipfire profile --sort=p95 --format=csv
wp snipfire profile --slow=20 # flag snippets from 20 ms
wp snipfire profile --reset # delete the measurements
wp snipfire profile --mode=off
--sort takes avg (default), p95, max, count, last, kb or id. See WP-CLI and REST API.
Developers can measure snippets their own way with the snipfire_observe_snippets, snipfire_snippet_start and snipfire_snippet_end hooks: see PHP hooks.
Something unclear or missing? Tell us