Commit ceb0361
committed
perf: optimize allocation rules evaluation from O(n²) to O(n)
Replace repeated Array.filter() and Array.find() operations with a
Map-based lookup system for deployment rules.
Changes:
- Add preprocessRules() function to create a Map for O(1) rule lookups
- Update isDeploymentWorthAllocatingTowards() to use preprocessed rules
- Update evaluateDeployments() to preprocess rules once before iteration
- Update matchingRuleExists() in AllocationManager to use optimized lookup
This eliminates quadratic complexity when evaluating thousands of
deployments against hundreds of rules.
Based on: #1147
Original author: madumas
Original commit: 2618f231 parent 6b4fa9e commit ceb0361
2 files changed
Lines changed: 45 additions & 12 deletions
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
1791 | 1792 | | |
1792 | 1793 | | |
1793 | 1794 | | |
1794 | | - | |
1795 | | - | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
1796 | 1803 | | |
1797 | 1804 | | |
1798 | 1805 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
162 | 186 | | |
163 | 187 | | |
164 | 188 | | |
| |||
192 | 216 | | |
193 | 217 | | |
194 | 218 | | |
| 219 | + | |
| 220 | + | |
195 | 221 | | |
196 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
197 | 228 | | |
198 | 229 | | |
199 | 230 | | |
200 | 231 | | |
201 | 232 | | |
202 | 233 | | |
203 | | - | |
| 234 | + | |
| 235 | + | |
204 | 236 | | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
| 237 | + | |
| 238 | + | |
213 | 239 | | |
214 | 240 | | |
215 | 241 | | |
| |||
0 commit comments