-
-
Notifications
You must be signed in to change notification settings - Fork 6
Improve performance #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
samdark
wants to merge
32
commits into
master
Choose a base branch
from
performance2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Improve performance #114
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
0973046
Add benchmarks
samdark dc72ee8
Optimize string definition normalization
samdark ec30e1d
Optimize array definition config parsing
samdark c347321
Optimize explicit definition checks
samdark 35905e6
Cache class-only array definitions
samdark 9fabe3f
Cache normalized references
samdark c307ee1
Cache callable definition dependencies
samdark 00a08b0
Cache parsed array definition keys
samdark 7f09ce4
Avoid build stack reset for explicit definitions
samdark a856499
Fast-path array definition class checks
samdark bb55c4e
Fast-path cached plain references
samdark ace9d0b
Fast-path array definition normalization
samdark ad619f1
Fast-path strict mode misses
samdark b47843e
Cache normalized static callables
samdark 3f3af1d
Avoid internal ArrayDefinition getter calls
samdark a7260e1
Cache normalized object values
samdark cbe0a4c
Cache normalized class definitions
samdark cc2999a
Fast-path cached plain reference strings
samdark 08107ba
Ensure psalm and full coverage pass
samdark 77f1708
Merge remote-tracking branch 'origin/master' into performance2
vjik 01f60ab
Apply PHP CS Fixer and Rector changes (CI)
vjik 5b20f85
Address comments
samdark c0508a6
Fix performance regression
samdark c827cd6
Fix test name
samdark a8c1f46
Add changelog
samdark 4311381
Fixes
samdark 95f18eb
Fixes
samdark 1583704
Fix edge case
samdark 4f9758a
Adjust benchmarks to be closer to reality. Remove unneeded optimizations
samdark 3dd134f
Refine performance changes after benchmarks
samdark a00b622
Stabilize benchmark sampling
samdark ff21c2a
Fix typo
samdark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "runner.bootstrap": "vendor/autoload.php", | ||
| "runner.path": "tests/Benchmark", | ||
| "runner.retry_threshold": 3, | ||
| "report.outputs": { | ||
| "csv_file": { | ||
| "extends": "delimited", | ||
| "delimiter": ",", | ||
| "file": "benchmarks.csv" | ||
| } | ||
| } | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,196 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Yiisoft\Definitions\Tests\Benchmark; | ||
|
|
||
| use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods; | ||
| use PhpBench\Benchmark\Metadata\Annotations\Groups; | ||
| use PhpBench\Benchmark\Metadata\Annotations\Iterations; | ||
| use PhpBench\Benchmark\Metadata\Annotations\Revs; | ||
| use Yiisoft\Definitions\DefinitionStorage; | ||
| use Yiisoft\Definitions\Tests\Support\Car; | ||
| use Yiisoft\Definitions\Tests\Support\ColorInterface; | ||
| use Yiisoft\Definitions\Tests\Support\ColorPink; | ||
| use Yiisoft\Definitions\Tests\Support\EngineInterface; | ||
| use Yiisoft\Definitions\Tests\Support\EngineMarkOne; | ||
| use Yiisoft\Test\Support\Container\SimpleContainer; | ||
|
|
||
| /** | ||
| * @Iterations(15) | ||
| * @Revs(1000) | ||
| * @BeforeMethods({"before"}) | ||
| */ | ||
| final class DefinitionStorageBench | ||
| { | ||
| private const SERVICE_COUNT = 200; | ||
|
|
||
| /** | ||
| * @var int[] | ||
| */ | ||
| private array $indexes = []; | ||
|
|
||
| /** | ||
| * @var array<string, string> | ||
| */ | ||
| private array $definitions = []; | ||
|
|
||
| private DefinitionStorage $explicitStorage; | ||
| private DefinitionStorage $resolvableStorage; | ||
| private DefinitionStorage $unresolvableStorage; | ||
| private DefinitionStorage $delegateStorage; | ||
| private DefinitionStorage $strictStorage; | ||
|
|
||
| public function before(): void | ||
| { | ||
| $this->indexes = []; | ||
| $this->definitions = [ | ||
| EngineInterface::class => EngineMarkOne::class, | ||
| ColorInterface::class => ColorPink::class, | ||
| ]; | ||
|
|
||
| for ($i = 0; $i < self::SERVICE_COUNT; $i++) { | ||
| $this->indexes[] = $i; | ||
| $this->definitions["service$i"] = Car::class; | ||
| } | ||
|
|
||
| $this->explicitStorage = new DefinitionStorage($this->definitions); | ||
| $this->resolvableStorage = new DefinitionStorage([ | ||
| EngineInterface::class => EngineMarkOne::class, | ||
| ]); | ||
| $this->unresolvableStorage = new DefinitionStorage(); | ||
| $this->delegateStorage = new DefinitionStorage(); | ||
| $this->delegateStorage->setDelegateContainer(new SimpleContainer([ | ||
| EngineInterface::class => new EngineMarkOne(), | ||
| ])); | ||
| $this->strictStorage = new DefinitionStorage([], true); | ||
|
|
||
| $this->resolvableStorage->has(Car::class); | ||
| $this->delegateStorage->has(Car::class); | ||
| } | ||
|
|
||
| /** | ||
| * Measures construction with a typical services map. | ||
| * | ||
| * @Groups({"construct", "storage"}) | ||
| */ | ||
| public function benchConstruct(): void | ||
| { | ||
| new DefinitionStorage($this->definitions); | ||
| } | ||
|
|
||
| /** | ||
| * Measures positive lookups of explicitly configured service IDs. | ||
| * | ||
| * @Groups({"lookup", "storage", "cold"}) | ||
| */ | ||
| public function benchSequentialExplicitLookupsColdStorage(): void | ||
| { | ||
| $storage = new DefinitionStorage($this->definitions); | ||
|
|
||
| foreach ($this->indexes as $index) { | ||
| $storage->has("service$index"); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Measures positive lookups against a reused definitions storage. | ||
| * | ||
| * @Groups({"lookup", "storage", "warm", "typical"}) | ||
| */ | ||
| public function benchSequentialExplicitLookupsWarmStorage(): void | ||
| { | ||
| foreach ($this->indexes as $index) { | ||
| $this->explicitStorage->has("service$index"); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Measures positive autowiring checks for an object graph. | ||
| * | ||
| * @Groups({"lookup", "storage", "autowire", "typical"}) | ||
| * @Revs(1000) | ||
| */ | ||
| public function benchResolvableObjectGraphColdStorage(): void | ||
| { | ||
| $storage = new DefinitionStorage([ | ||
| EngineInterface::class => EngineMarkOne::class, | ||
| ]); | ||
|
|
||
| $storage->has(Car::class); | ||
| } | ||
|
|
||
| /** | ||
| * Measures positive autowiring checks for an object graph against reused storage. | ||
| * | ||
| * @Groups({"lookup", "storage", "autowire", "warm", "typical"}) | ||
| * @Revs(10000) | ||
| */ | ||
| public function benchResolvableObjectGraphWarmStorage(): void | ||
| { | ||
| $this->resolvableStorage->has(Car::class); | ||
| } | ||
|
|
||
| /** | ||
| * Measures negative autowiring checks for a missing dependency. | ||
| * | ||
| * @Groups({"lookup", "storage", "autowire", "typical"}) | ||
| * @Revs(1000) | ||
| */ | ||
| public function benchUnresolvableObjectGraphColdStorage(): void | ||
| { | ||
| $storage = new DefinitionStorage(); | ||
|
|
||
| $storage->has(Car::class); | ||
| } | ||
|
|
||
| /** | ||
| * Measures negative autowiring checks for a missing dependency against reused storage. | ||
| * | ||
| * @Groups({"lookup", "storage", "autowire", "warm", "typical"}) | ||
| * @Revs(1000) | ||
| */ | ||
| public function benchUnresolvableObjectGraphWarmStorage(): void | ||
| { | ||
| $this->unresolvableStorage->has(Car::class); | ||
| } | ||
|
|
||
| /** | ||
| * Measures fallback through a delegate container when a dependency is not explicitly defined. | ||
| * | ||
| * @Groups({"lookup", "storage", "delegate", "typical"}) | ||
| * @Revs(1000) | ||
| */ | ||
| public function benchResolvableObjectGraphWithDelegateColdStorage(): void | ||
| { | ||
| $storage = new DefinitionStorage(); | ||
| $storage->setDelegateContainer(new SimpleContainer([ | ||
| EngineInterface::class => new EngineMarkOne(), | ||
| ])); | ||
|
|
||
| $storage->has(Car::class); | ||
| } | ||
|
|
||
| /** | ||
| * Measures fallback through a delegate container against reused storage. | ||
| * | ||
| * @Groups({"lookup", "storage", "delegate", "warm", "typical"}) | ||
| * @Revs(10000) | ||
| */ | ||
| public function benchResolvableObjectGraphWithDelegateWarmStorage(): void | ||
| { | ||
| $this->delegateStorage->has(Car::class); | ||
| } | ||
|
|
||
| /** | ||
| * Measures strict mode misses where class names are not implicitly resolvable. | ||
| * | ||
| * @Groups({"lookup", "storage", "strict"}) | ||
| */ | ||
| public function benchStrictModeClassMisses(): void | ||
| { | ||
| foreach ($this->indexes as $_index) { | ||
| $this->strictStorage->has(EngineMarkOne::class); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.