Skip to content

[6.x] Look up each tree page's entry once when building the CP tree - #15812

Open
DanielDarrenJones wants to merge 1 commit into
statamic:6.xfrom
DanielDarrenJones:perf/6x-cp-tree-transform
Open

DanielDarrenJones wants to merge 1 commit into
statamic:6.xfrom
DanielDarrenJones:perf/6x-cp-tree-transform

Conversation

@DanielDarrenJones

Copy link
Copy Markdown
Contributor

The navigation and collection tree endpoints transform every page with TreeBuilder::transformTreeForController(). For each page it looked the entry up again for almost every key it filled in, fetched the entry's blueprint twice, and resolved the current user for every page.

It now looks the entry and blueprint up once per page and the user once per level, in a plain loop. The output is the same.

Benchmark

A generated site on 6.40.0. Each request runs in its own PHP process, as PHP-FPM serves it (boot not timed, opcache on), median of 5, on an M1 Pro with PHP 8.5.

  • Nav tree with 4,680 items: 506 ms → 459 ms
  • Collection tree with 319 pages: 92 ms → 83 ms

The JSON is byte-identical to stock, and the tree pages render identically in the CP.

Tests

ViewNavigationTreeTest asserts the exact JSON for a tree with entry pages, a custom title, a redirect, a draft, a nested child, a link, a text-only page, a missing entry, and a user who can't delete entries. It passes both before and after the change.

The full suite passes.

This branch has not been deployed

No deployments
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