This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Fabien Potencier 0c5b83ab95 feature #18359 [Form] [DoctrineBridge] optimized LazyChoiceList and DoctrineChoiceLoader (HeahDude)
This PR was merged into the 3.1-dev branch.

Discussion
----------

[Form] [DoctrineBridge] optimized LazyChoiceList and DoctrineChoiceLoader

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | ~
| License       | MIT
| Doc PR        | ~

Problem
======
Actually we got a circular dependency:

| Object | Return
|----------|-------------|
|`DefaultChoiceListFactory::createListFromLoader()` (decorated) | `LazyChoiceList` with loader and resolved `$value`
| `LazyChoiceList::get*` | `DoctrineChoiceLoader` with resolved `$value`
`DoctrineChoiceLoader::loadChoiceList()` | (decorated) `DefaultChoiceListFactory` with loaded choices and resolved `$value`
`DefaultChoiceListFactory::createListFromChoices()` | `ArrayChoiceList` with `resolved `$value`

With this refactoring, the `DoctrineChoiceLoader` is no longer dependant to the factory, the `ChoiceLoaderInterface::loadChoiceList()` must return a `ChoiceListInterface` but should not need a decorated factory while `$value` is already resolved. It should remain lazy IMHO.

Solution
======

| Object | Return |
|----------|-----------|
| `DefaultChoiceListFactory::createListFromLoader()` | `LazyChoiceList` with loader and resolved `$value`
| `LazyChoiceList::get*()` | `DoctrineChoiceLoader` with resolved `$value`
| `DoctrineChoiceLoader::loadChoiceList()` | `ArrayChoiceList` with resolved `$value`.

Since `choiceListFactory` is a private property, this change should be safe regarding BC.

To justify this change, I've made some blackfire profiling.
You can see my [branch of SE here](https://github.com/HeahDude/symfony-standard/tree/test/optimize-doctrine_choice_loader) and the [all in file test implementation](https://github.com/HeahDude/symfony-standard/blob/test/optimize-doctrine_choice_loader/src/AppBundle/Controller/DefaultController.php).

Basically it loads a form with 3 `EntityType` fields with different classes holding 50 instances each.

(INIT events are profiled with an empty cache)

When | What | Diff (SE => PR)
--------|-------|------
INIT (1) | build form (load types) | [see](https://blackfire.io/profiles/compare/061d5d28-15c6-4e01-b8c0-3edc9cb8daf0/graph)
INIT (2) | build view (load choices) | [see](https://blackfire.io/profiles/compare/04f142a8-d886-405a-be4d-636ba82d8acd/graph)
CACHED | build form (load types) | [see](https://blackfire.io/profiles/compare/293b27b6-aa58-42ae-bafb-655513201505/graph)
CACHED | build view (load choices) | [see](https://blackfire.io/profiles/compare/e5b37dfe-cc9e-498f-b98a-7448830ad190/graph)
SUBMIT | build form (load types) | [see](https://blackfire.io/profiles/compare/7f3baea9-0d27-46b6-8c24-c577742382dc/graph)
SUBMIT | handle request (load choices) | [see](https://blackfire.io/profiles/compare/8644ebfb-4397-495b-8f3d-1a6e1d7f8476/graph)
SUBMIT | build view (load values) | [see](https://blackfire.io/profiles/compare/89c3cc7c-ea07-4300-91b3-99004cb58ea1/graph)

(1):
![build_form-no_cache](https://cloud.githubusercontent.com/assets/10107633/14136166/b5a85eb8-f661-11e5-8556-3e0dcbfaf404.jpg)
(2):
![build_view-no_cache](https://cloud.githubusercontent.com/assets/10107633/14136240/1162f3ee-f662-11e5-834a-1ed1e519dc83.jpg)

It can seem like 1 and 2 balance each other but it comes clear when comparing values:

| -  | Build form | Build view |
|-----|---------|--------------|
| wall time | -88 ms | +9.71 ms
| blocking I/O | -40 ms | +3.67 ms
| cpu | -48 ms | +13.4 ms
| memory | -4.03 MB | +236 kB
| network | -203 B | +2.21 kB

Commits
-------

98621f4 [Form] optimized LazyChoiceList
86b2ff1 [DoctrineBridge] optimized DoctrineChoiceLoader
2016-04-28 12:16:40 +02:00
.composer Merge branch '2.3' into 2.7 2016-04-02 09:48:01 +02:00
.github Improved the "branch" row of the PR table 2016-03-13 12:02:32 +01:00
src/Symfony feature #18359 [Form] [DoctrineBridge] optimized LazyChoiceList and DoctrineChoiceLoader (HeahDude) 2016-04-28 12:16:40 +02:00
.editorconfig Add EditorConfig File 2012-06-16 14:08:15 +02:00
.gitignore Add appveyor.yml for C.I. on Windows 2015-08-25 23:41:37 +02:00
.php_cs use nowdoc instead of heredoc 2015-12-21 17:05:00 +01:00
.travis.php [Cache] Symfony PSR-6 implementation 2016-01-19 08:02:17 +01:00
.travis.yml Merge branch '3.0' 2016-04-25 13:21:08 +02:00
appveyor.yml Merge branch '3.0' 2016-04-25 13:21:08 +02:00
CHANGELOG-3.0.md Merge branch '3.0' 2016-03-31 10:13:34 +02:00
composer.json Merge branch '3.0' 2016-04-02 10:08:03 +02:00
CONTRIBUTING.md Update contributing docs 2016-02-24 15:36:06 +01:00
CONTRIBUTORS.md update CONTRIBUTORS for 2.3.39 2016-03-13 17:37:49 +01:00
LICENSE Update copyright year 2016-01-01 23:53:47 -03:00
phpunit [2.8] fix mocks 2016-03-27 11:27:49 +02:00
phpunit.xml.dist Merge branch '3.0' 2016-03-16 18:16:29 +01:00
README.md Merge branch '2.8' 2015-06-04 22:30:47 +02:00
UPGRADE-3.0.md Fix leftover conflict marker in UPGRADE-3.0.md 2016-03-14 22:24:56 +01:00
UPGRADE-3.1.md feature #18357 [Form] Let TextType implement DataTransformerInterface (HeahDude) 2016-04-28 12:07:03 +02:00
UPGRADE-4.0.md [FrameworkBundle] Minor UPGRADE files fix 2016-04-27 09:34:05 +02:00

README

What is Symfony?

Symfony is a PHP full-stack web framework. It is written with speed and flexibility in mind. It allows developers to build better and easy to maintain websites with PHP.

Symfony can be used to develop all kind of websites, from your personal blog to high traffic ones like Dailymotion or Yahoo! Answers.

Installation

The best way to install Symfony is to use the official Symfony Installer. It allows you to start a new project based on the version you want.

Documentation

The "Quick Tour" tutorial gives you a first feeling of the framework. If, like us, you think that Symfony can help speed up your development and take the quality of your work to the next level, read the official Symfony documentation.

Contributing

Symfony is an open source, community-driven project. If you'd like to contribute, please read the Contributing Code part of the documentation. If you're submitting a pull request, please follow the guidelines in the Submitting a Patch section and use Pull Request Template.

Running Symfony Tests

Information on how to run the Symfony test suite can be found in the Running Symfony Tests section.