Commit 2618f23
committed
perf: optimize allocation rules evaluation from O(n²) to O(n)
Replace repeated Array.filter() + Array.find() with Map-based lookup for deployment rules.
- Add preprocessRules() function to create Map for O(1) rule lookups
- Update isDeploymentWorthAllocatingTowards() to use pre-processed rules Map
- Update evaluateDeployments() to preprocess rules once instead of per deployment
- Update AllocationManager.matchingRuleExists() to use optimized lookup
Performance improvement:
- Before: O(n²) - filter + find for each deployment evaluation
- After: O(n) - single preprocessing + O(1) lookups per deployment
- Significant speedup when evaluating many deployments against many rules
Fixes performance bottleneck in allocation rule evaluation where processing
thousands of deployments with hundreds of rules resulted in quadratic complexity.1 parent bea354e commit 2618f23
File tree
2 files changed
+54
-13
lines changed- packages/indexer-common/src
- indexer-management
2 files changed
+54
-13
lines changedLines changed: 10 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| |||
1791 | 1792 | | |
1792 | 1793 | | |
1793 | 1794 | | |
1794 | | - | |
1795 | | - | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
1796 | 1804 | | |
1797 | 1805 | | |
1798 | 1806 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
190 | 213 | | |
191 | 214 | | |
192 | 215 | | |
193 | 216 | | |
194 | 217 | | |
195 | | - | |
196 | | - | |
197 | | - | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
198 | 235 | | |
199 | 236 | | |
200 | 237 | | |
201 | 238 | | |
202 | 239 | | |
203 | 240 | | |
| 241 | + | |
| 242 | + | |
204 | 243 | | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
| 244 | + | |
| 245 | + | |
213 | 246 | | |
214 | 247 | | |
215 | 248 | | |
| |||
0 commit comments