Developer-Dashboard

 view release on metacpan or  search on metacpan

script/problem48-saved-page-route-benchmark  view on Meta::CPAN

        path        => '/app/welcome',
        query       => '',
        remote_addr => '127.0.0.1',
        headers     => { host => '127.0.0.1' },
    );
}

# _normalized_body($body)
# Replaces only the live clock text so repeated page bodies can be compared.
# Input: scalar HTML response body.
# Output: normalized scalar HTML; malformed response bodies throw an error.
sub _normalized_body {
    my ($body) = @_;
    die "Saved page route returned a non-scalar response body\n" if !defined $body || ref($body);
    my $normalized = $body;
    my $matches = $normalized =~ s{(<span id="status-datetime">)[^<]*(</span>)}{$1<TIMESTAMP>$2};
    die "Saved page response did not contain exactly one live timestamp\n" if $matches != 1;
    return $normalized;
}

# _median(@samples)
# Returns the center duration from the odd-sized benchmark sample set.
# Input: elapsed durations in seconds.
# Output: median elapsed duration in seconds.
sub _median {
    my @samples = sort { $a <=> $b } @_;
    die "Cannot calculate a median without samples\n" if !@samples;
    return $samples[ int( @samples / 2 ) ];
}

# _usage()
# Describes workload, source selection, and profiler requirements.
# Input: none.
# Output: command-line usage string.
sub _usage {
    return "Usage: P48_LIB=<lib> $0 [--iterations N] [--runs ODD_N] [--nav-fragments N] [--skill-nav-fragments N] [--indicators N] [--profile|--no-profile] [--no-prompt-summary-cache] [--no-nav-cache] [--no-nav-fragment-cache] [--no-skill-literal-nav...
      . "Measures the warmed production /app/welcome route with saved and installed-skill nav fragments in a private HOME.\n"
      . "Only the live status timestamp is normalized for exact repeat parity. Set P48_LIB to select v5.88 or current source.\n"
      . "Use --indicators N to configure synthetic collector indicators and --no-prompt-summary-cache for the exact-output comparison control.\n"
      . "Use --profile with perl -d:NYTProf and NYTPROF=start=no to profile only the warmed route loop.\n";
}

__END__

=pod

=head1 NAME

problem48-saved-page-route-benchmark - profile a saved browser page and its navigation fragments

=head1 PURPOSE

Measures the warmed production C<Web::App-E<gt>handle('/app/welcome')> path
with a configurable number of saved C<nav/*.tt> fragments, an isolated temporary HOME, strict
HTTP/body validation, configurable installed-skill navigation fragments, and
optional collector indicators and NYTProf profiling.

=head1 WHY IT EXISTS

Problem 48 needs performance evidence at ordinary application boundaries, not
only the status endpoint. This tool compares the same fixture on v5.88 and the
current source tree and supports larger nav sets to measure how per-request
root discovery scales. It normalizes only the live status timestamp, then
requires the remainder of every response to stay byte-identical during the
run.

=head1 WHEN TO USE

Run after changes to saved-page routing, Template Toolkit preparation, page
chrome, saved navigation discovery, or request-local runtime caches. Compare
the output from both source trees before attributing a speedup to a change.
The report includes nav candidate-root searches, nav file reads, and containment
checks so cache and provenance effects remain distinguishable.
Output distinguishes requested snapshot caching from observed hits and reports
whether the optional native watch backend is available. Use C<--no-native-watch>
to benchmark the portable fallback explicitly on a system that has the native
backend installed.
Use C<--indicators> to seed collector-managed indicator records and measure the
prompt-summary freshness cache under status-heavy page rendering. The cache
control C<--no-prompt-summary-cache> disables only prompt-summary reuse; the
benchmark reports freshness-check and cache-hit counts and requires the same
response bytes in both modes.
Use C<--skill-nav-fragments> to create temporary installed skills with one raw
navigation fragment each. The report verifies that every fixture fragment was
rendered by the real route; this isolates the skill-navigation discovery and
rendering path without reading user skill directories.
Use C<--no-nav-cache> on current source to compare the same fixture with nav
inventory rescanning on every request; the output reports scan count.
Use C<--no-nav-fragment-cache> to clear the bounded literal-fragment cache
before each request and compare the file-read count and latency with the
validated-cache path.
Use C<--no-skill-literal-nav-cache> to disable reuse of unchanged static
skill-nav pages while preserving skill discovery and exact rendered output.
The report includes the number of skill-nav instruction reads, making the
warm-cache effect measurable.
Use C<--no-skill-nav-inventory-cache> to rescan the skill-nav directory tree on
every request. Compare it with the metadata-validated directory inventory
cache; both modes preserve exact response bytes, and the report records actual
recursive directory scans.
Use C<--duplicate-page-containment> to recreate the former extra containment
check in candidate lookup, so exact-output route measurements can compare its
cost with the single validation at secure open time. Output reports the total
containment checks during measured requests.
Use C<--no-page-roots-cache> to disable the request-local saved-page root
snapshot for page lookups that do not have a supplying-layer provenance hint.
Saved nav files use their scanned layer provenance and do not repeat candidate
root search. Output reports the number of measured calls to C<dashboards_roots>.
Use C<--duplicate-skill-layer-resolution> to recreate the former second
layer lookup in C<_load_skill_page>; compare its layer-resolution count and
route timing with the optimized path while checking response hash parity.
Use C<--duplicate-skill-nav-layer-resolution> to recreate repeated layer
resolution while enumerating and loading each skill navigation fragment.
Use C<--legacy-skill-nav-enumeration> to replay the former per-skill discovery
loop against the same fixture. The benchmark reports layer-resolution counts
and requires exact response parity with the bulk-inventory path.
Use C<--parse-raw-skill-nav> as a control that forces raw skill nav templates
through the structured instruction parser rather than the raw-fragment path.
Use C<--legacy-runtime-root-access> as the pre-cache control for the
request-scoped runtime-root accessor.
Use C<--legacy-config-snapshot-signature> as the prior pretty-JSON control for
the request-local configuration snapshot key; the response bytes must match.



( run in 1.346 second using v1.01-cache-2.11-cpan-eb134014566 )