[Toolkit] Stop re-walking the filesystem on every Recipe::getFiles() - #3780
Open
Kocal wants to merge 1 commit into
Open
[Toolkit] Stop re-walking the filesystem on every Recipe::getFiles()#3780Kocal wants to merge 1 commit into
Kocal wants to merge 1 commit into
Conversation
Member
Author
|
With #3772, Toolkit unit tests went from ~1m35s to ~33s \o/ |
Kocal
force-pushed
the
perf/toolkit-component-template-index
branch
3 times, most recently
from
August 15, 2026 22:21
3474530 to
045a496
Compare
| Q | A
| -------------- | ---
| Bug fix? | no
| New feature? | no
| Deprecations? | no
| Documentation? | no
| Issues | -
| License | MIT
`Recipe::getFiles()` is a generator that runs a `Finder` over the recipe
directories every time it is iterated. It has six consumers, and several of
them iterate the same recipe more than once: `RecipeDocRenderer` walks it
twice while building one doc context, on top of the walk `PoolResolver` just
did, and `ComponentFactory::metadataFor()` reaches it once per anonymous
component lookup.
Build the list once per `Recipe` and return it. `Recipe` is `@internal`,
immutable, and constructed per kit load from read-only sources, so there is
nothing to invalidate. The return type is already `iterable<File>`, so
returning an array is signature-compatible and the `iterator_to_array()` call
sites keep working.
Resolving the shadcn kit's components went from 22,140 `Finder` walks to one
per recipe. The Toolkit test suite goes from ~13.3 s to ~9.5 s.
Benchmarked on the rendering test suite, from `src/Toolkit`:
```bash
blackfire run --ignore-exit-status symfony php vendor/bin/phpunit \
--filter 'Kit shadcn, component [a-d]'
```
Blackfire:
- before — 19.2s wall / 245MB: https://app.blackfire.io/envs/5f4f9a62-eaa0-45ee-b7b3-a1b879f550e9/profiles/ddc20fda-bf4c-4344-9037-0dc0054d496a/graph
- after — 16.2s wall / 210MB: https://app.blackfire.io/envs/5f4f9a62-eaa0-45ee-b7b3-a1b879f550e9/profiles/2f7d0363-b44a-4a2b-80e6-8f1ed92bc7fb/graph
- diff: https://app.blackfire.io/envs/5f4f9a62-eaa0-45ee-b7b3-a1b879f550e9/profiles/compare/ddc20fda-bf4c-4344-9037-0dc0054d496a...2f7d0363-b44a-4a2b-80e6-8f1ed92bc7fb/graph
Analysis, implementation and benchmarks by Claude Opus 5.
Kocal
force-pushed
the
perf/toolkit-component-template-index
branch
from
August 15, 2026 22:56
045a496 to
f807b3d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Recipe::getFiles()is a generator that runs aFinderover the recipedirectories every time it is iterated. It has six consumers, and several of
them iterate the same recipe more than once:
RecipeDocRendererwalks ittwice while building one doc context, on top of the walk
PoolResolverjustdid, and
ComponentFactory::metadataFor()reaches it once per anonymouscomponent lookup.
Build the list once per
Recipeand return it.Recipeis@internal,immutable, and constructed per kit load from read-only sources, so there is
nothing to invalidate. The return type is already
iterable<File>, soreturning an array is signature-compatible and the
iterator_to_array()callsites keep working.
Resolving the shadcn kit's components went from 22,140
Finderwalks to oneper recipe. The Toolkit test suite goes from ~13.3 s to ~9.5 s.
Benchmarked on the rendering test suite, from
src/Toolkit:blackfire run --ignore-exit-status symfony php vendor/bin/phpunit \ --filter 'Kit shadcn, component [a-d]'Blackfire:
Analysis, implementation and benchmarks by Claude Opus 5.