Skip to content

perf: stop the profiler at init for visitors who cannot see its output - #148

Merged
dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:perf/profiler-logged-in
Oct 22, 2026
Merged

dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:perf/profiler-logged-in

Conversation

@Contributolo

Copy link
Copy Markdown
Collaborator

?blockstudio-perf (or the dev/perf setting) turns on the profiler for every visitor, and output is only gated later in can_finalize() (includes/classes/perf.php). Anonymous visitors on a public site still pay for every timer and track call on the page, and the data is then thrown away. Perf::init() runs while plugins load, before pluggable functions exist, so the user cannot be checked there.

The fix keeps the early start, so the total timing is unchanged. It adds Perf::maybe_deactivate() on init at the earliest priority, where WordPress has just set the current user and before Blockstudio's build and render phases run. If the request may not receive the output under the existing can_finalize() rules, the profiler switches off and drops what it has. Editors and anonymous local probes behave exactly as before.

Measured on a page with nine blocks: an anonymous remote request with the query argument went from 40 recorded track calls in 14 groups to none. Editor output, including the total, is unchanged. This is mostly hygiene, the saved work per request is small.

Test: PerfTest::test_query_probe_stops_at_init_for_visitors_who_cannot_receive_output (anonymous remote, anonymous local, editor remote).

The query argument started the profiler for every visitor. Switch it off
at init, once the current user is known, when the output would be
discarded.
@dnnsjsk
dnnsjsk merged commit 7b0a3c6 into inline0:main Oct 22, 2026
@dnnsjsk

dnnsjsk commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Included in Blockstudio 7.7.6, now officially released. This PR is merged into main as part of the reviewed release, with full CI and distribution checks passing for the release commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants