Commit 0c5b83a
committed
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):

(2):

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 DoctrineChoiceLoaderFile tree
4 files changed
+154
-47
lines changed- src/Symfony
- Bridge/Doctrine/Form
- ChoiceList
- Type
- Component/Form
- ChoiceList
- Tests/ChoiceList
4 files changed
+154
-47
lines changedLines changed: 18 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
63 | | - | |
64 | | - | |
65 | 64 | | |
66 | 65 | | |
67 | 66 | | |
68 | 67 | | |
69 | 68 | | |
| 69 | + | |
| 70 | + | |
70 | 71 | | |
71 | 72 | | |
72 | | - | |
| 73 | + | |
73 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
74 | 87 | | |
75 | 88 | | |
76 | | - | |
77 | 89 | | |
78 | 90 | | |
79 | 91 | | |
| |||
93 | 105 | | |
94 | 106 | | |
95 | 107 | | |
96 | | - | |
97 | | - | |
98 | | - | |
| 108 | + | |
99 | 109 | | |
100 | 110 | | |
101 | 111 | | |
| |||
146 | 156 | | |
147 | 157 | | |
148 | 158 | | |
149 | | - | |
| 159 | + | |
150 | 160 | | |
151 | 161 | | |
152 | 162 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
164 | 163 | | |
165 | 164 | | |
166 | 165 | | |
| |||
Lines changed: 78 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
51 | 60 | | |
52 | 61 | | |
53 | 62 | | |
| |||
70 | 79 | | |
71 | 80 | | |
72 | 81 | | |
73 | | - | |
74 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
75 | 90 | | |
76 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
77 | 96 | | |
| 97 | + | |
| 98 | + | |
78 | 99 | | |
79 | 100 | | |
80 | 101 | | |
81 | 102 | | |
82 | 103 | | |
83 | 104 | | |
84 | 105 | | |
85 | | - | |
86 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
87 | 113 | | |
88 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
89 | 119 | | |
| 120 | + | |
| 121 | + | |
90 | 122 | | |
91 | 123 | | |
92 | 124 | | |
93 | 125 | | |
94 | 126 | | |
95 | 127 | | |
96 | 128 | | |
97 | | - | |
98 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
99 | 136 | | |
100 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
101 | 142 | | |
| 143 | + | |
| 144 | + | |
102 | 145 | | |
103 | 146 | | |
104 | 147 | | |
105 | 148 | | |
106 | 149 | | |
107 | 150 | | |
108 | 151 | | |
109 | | - | |
110 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
111 | 159 | | |
112 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
113 | 165 | | |
| 166 | + | |
| 167 | + | |
114 | 168 | | |
115 | 169 | | |
116 | 170 | | |
117 | 171 | | |
118 | 172 | | |
119 | 173 | | |
120 | 174 | | |
121 | | - | |
122 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
123 | 182 | | |
124 | 183 | | |
125 | | - | |
| 184 | + | |
126 | 185 | | |
127 | 186 | | |
128 | 187 | | |
129 | 188 | | |
130 | 189 | | |
131 | 190 | | |
132 | 191 | | |
133 | | - | |
134 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
135 | 199 | | |
136 | 200 | | |
137 | | - | |
| 201 | + | |
138 | 202 | | |
139 | 203 | | |
0 commit comments