Skip to content

Add CodSpeed continuous benchmarking for the build pipeline - #87

Closed
shenxianpeng wants to merge 3 commits into
mainfrom
claude/mkdocs-issue-4167-15dhse
Closed

shenxianpeng wants to merge 3 commits into
mainfrom
claude/mkdocs-issue-4167-15dhse

Conversation

@shenxianpeng

Copy link
Copy Markdown
Member

Establishes a measured performance baseline before starting optimization work on the build pipeline (upstream issue mkdocs/mkdocs#3695).

What's included

  • benchmarks/ suite (pytest + pytest-codspeed, new hatch env bench) covering the real hot paths:
    • clean full builds of synthetic sites at 10/50/200 pages (config loading included, matching the mkdocs serve rebuild loop)
    • dirty rebuild (mkdocs serve --dirty inner-loop proxy)
    • single Page.render() call — exposes the per-page markdown.Markdown construction overhead
    • single page Jinja render with a large nav — exposes the O(N²) sitewide rendering term
    • search index population + serialization
    • file discovery + navigation construction
  • .github/workflows/codspeed.yml — runs the suite under CodSpeed instrumentation on pushes to main and PRs (SHA-pinned CodSpeedHQ/action v5.0.3, following repo convention)
  • hatch run bench:test (smoke) / hatch run bench:codspeed (measure); sizes overridable via MKDOCS_BENCH_SIZES; docs in benchmarks/README.md and CONTRIBUTING.md

Baseline numbers (wall-time fallback, Linux container, CPython 3.11)

Benchmark Time (best)
full build, 10 pages 212 ms
full build, 50 pages 384 ms
full build, 200 pages 1.44 s
dirty rebuild (50 pages, no changes) 61 ms
get_files + nav (200 pages) 6.2 ms
single page markdown render 1.8 ms
single page template render (200-page nav) 1.9 ms
search index (200 pages) 82 ms

Scaling study (MKDOCS_BENCH_SIZES=100,400,1600, full build only):

Pages Time ms / page
100 0.78 s 7.8
400 3.71 s 9.3
1600 35.3 s 22.1

4× the pages costs 9.5× the time — the superlinear growth from mkdocs/mkdocs#3695, driven by the O(N²) nav rendering term. This is the baseline the upcoming optimization PRs will be measured against.

One-time manual setup required (@shenxianpeng)

  1. Log in to codspeed.io with GitHub and install the CodSpeed GitHub App on mkdocs-ng/mkdocs.
  2. Copy the project token from the CodSpeed dashboard into a repo secret named CODSPEED_TOKEN (this is the repository's first secret).
  3. After merge, the first push to main establishes the instrumented baseline; subsequent PRs get automatic performance-comparison comments.

Until the app/token is set up, the workflow's benchmark run still executes; only the report upload is affected.

Verification

  • hatch run bench:test equivalent passes (8 benchmarks), ruff/isort/markdownlint clean
  • Existing unittest suites unaffected (no production code changed)
  • python -m build confirms benchmarks/ is not shipped in the wheel

Related Issue

Groundwork for upstream mkdocs/mkdocs#3695 (build/serve performance).

Checklist

  • New tests added for new behavior (if applicable) — the benchmark suite itself
  • Documentation updated (if applicable)
  • Release notes docs/about/release-notes.md updated (if applicable)

🤖 Generated with Claude Code

https://claude.ai/code/session_018Hw7x9BxxpuKiLkzjLczp9


Generated by Claude Code

Establish a measured performance baseline before starting optimization
work on the build pipeline (upstream issue mkdocs/mkdocs#3695).

The new benchmarks/ suite (pytest + pytest-codspeed, hatch env 'bench')
covers the real hot paths:

* clean full builds of synthetic sites at 10/50/200 pages, config
  loading included to match the 'mkdocs serve' rebuild loop
* a dirty rebuild ('mkdocs serve --dirty' inner-loop proxy)
* a single Page.render() call (exposes the per-page markdown.Markdown
  construction overhead)
* a single page's Jinja template render with a large nav (exposes the
  O(N^2) sitewide rendering term)
* search index population and serialization
* file discovery and navigation construction

Synthetic sites are generated on the fly with realistic Markdown
(headings, prose, fenced code, cross-page and anchor links). Site sizes
are overridable via MKDOCS_BENCH_SIZES for local scaling studies.

The suite intentionally avoids importing mkdocs.tests (whose package
init installs a logging handler that raises on warnings) and runs on a
single Python version for comparability. benchmarks/ is not shipped in
the wheel or sdist.

CI: new codspeed.yml workflow runs the suite under CodSpeed
instrumentation on pushes to main and pull requests, giving every PR an
automatic performance comparison against main once the CodSpeed GitHub
App is installed and the CODSPEED_TOKEN secret is set.

Local wall-time baseline (this machine, Python 3.11): full build
212ms/384ms/1.44s at 10/50/200 pages; scaling study 100/400/1600 pages:
0.78s/3.7s/35.3s, i.e. 7.8/9.3/22.1 ms per page - the superlinear
growth reported in mkdocs/mkdocs#3695.
@codspeed

codspeed Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Congrats! CodSpeed is installed 🎉

🆕 8 new benchmarks were detected.

You will start to see performance impacts in the reports once the benchmarks are run from your default branch.

Detected benchmarks


Open in CodSpeed

Copy link
Copy Markdown
Member Author

Superseded by #88 (the CodSpeed wizard PR), which was merged as the base benchmark setup — its OIDC authentication needs no token secret and its 23 micro-benchmarks give finer-grained regression attribution.

The pieces unique to this PR (size-parametrized full builds for scaling studies, the dirty-rebuild serve-loop proxy, and a large-nav template render that actually exposes the O(N²) term from mkdocs/mkdocs#3695) will follow as an incremental PR on top of the merged structure. The baseline scaling numbers measured here (100/400/1600 pages → 7.8/9.3/22.1 ms per page) remain valid reference data.


Generated by Claude Code

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.

1 participant