Repository navigation
Commit d991ff3
perf(plan): single-pass clipping in remove_intersecting_windows, refresh random reference
Removes the "clip again" loop. It re-ran the whole clipping pass over every
charge window whenever a split left a tail long enough to keep, copying both
window lists each time. With export windows processed in start order the retry
cannot find anything: a head segment emitted by a split ends at the current
export window's start, and every later export window starts at or after that,
so nothing can reach back into it. Export windows are sorted here rather than
assumed sorted, so correctness does not depend on the caller.
This is not a speed-up - the benchmark is unchanged at 4.30s mean, so the retry
was rarely triggering. It is a simplification and a latent bug fix: on unsorted
input the old loop could emit a charge window overlapping an enabled export
window and then fail to revisit it, because the retry was only armed when the
remaining tail was at least 5 minutes long.
Verified by differential testing the new implementation against the original
from main over 300,000 random window layouts with sorted export windows (the
invariant callers provide): zero mismatches. Repeating with deliberately
unsorted export windows produces 495 disagreements in 200,000 layouts, and in
every one it is the old implementation that leaves a charge window overlapping
an enabled export.
The in-repo randomised equivalence test now generates sub-5-minute windows,
zero-length gaps and overlapping export windows, and runs 1000 layouts. Two
faults in its naive reference surfaced as a result and are fixed: an unclipped
window shorter than 5 minutes is kept rather than discarded, and windows that
merely touch at a boundary overlap arithmetically but clip nothing, so they
must not arm the minimum-length rule.
Also refreshes cases/random_results.json, which run_random compares against.
It was recorded on 2026-08-09 against the previous scenario set and was left
stale when the scenarios were regenerated in #4491, so run_random reported
large differences that were purely the scenario mismatch. Regenerated from the
current scenarios; the plans are identical with and without this change, so the
new reference is equally valid for main.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent 54dd46e commit d991ff3
3 files changed
Lines changed: 353 additions & 257 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| |||
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
| 86 | + | |
85 | 87 | | |
86 | | - | |
| 88 | + | |
87 | 89 | | |
88 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
89 | 96 | | |
90 | 97 | | |
91 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
92 | 101 | | |
93 | 102 | | |
94 | 103 | | |
| |||
185 | 194 | | |
186 | 195 | | |
187 | 196 | | |
188 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
189 | 290 | | |
190 | | - | |
191 | | - | |
192 | | - | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
193 | 294 | | |
194 | 295 | | |
195 | 296 | | |
196 | 297 | | |
197 | | - | |
| 298 | + | |
198 | 299 | | |
199 | | - | |
200 | | - | |
| 300 | + | |
| 301 | + | |
201 | 302 | | |
202 | 303 | | |
203 | | - | |
| 304 | + | |
204 | 305 | | |
205 | | - | |
| 306 | + | |
206 | 307 | | |
207 | | - | |
208 | | - | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
209 | 313 | | |
210 | 314 | | |
211 | 315 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
993 | 993 | | |
994 | 994 | | |
995 | 995 | | |
996 | | - | |
997 | | - | |
998 | | - | |
999 | | - | |
1000 | | - | |
1001 | | - | |
1002 | | - | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
1003 | 1012 | | |
1004 | 1013 | | |
1005 | | - | |
| 1014 | + | |
1006 | 1015 | | |
1007 | 1016 | | |
1008 | 1017 | | |
1009 | 1018 | | |
1010 | 1019 | | |
1011 | | - | |
| 1020 | + | |
| 1021 | + | |
1012 | 1022 | | |
1013 | 1023 | | |
1014 | | - | |
1015 | | - | |
1016 | | - | |
1017 | | - | |
1018 | | - | |
1019 | | - | |
1020 | | - | |
1021 | | - | |
1022 | | - | |
1023 | | - | |
1024 | | - | |
1025 | | - | |
1026 | | - | |
1027 | | - | |
1028 | | - | |
1029 | | - | |
1030 | | - | |
1031 | | - | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
1032 | 1038 | | |
1033 | | - | |
1034 | | - | |
1035 | | - | |
1036 | | - | |
1037 | | - | |
1038 | | - | |
1039 | | - | |
1040 | | - | |
1041 | | - | |
1042 | | - | |
1043 | | - | |
1044 | | - | |
1045 | | - | |
1046 | | - | |
1047 | | - | |
1048 | | - | |
1049 | | - | |
1050 | | - | |
1051 | | - | |
1052 | | - | |
1053 | | - | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
1054 | 1045 | | |
1055 | 1046 | | |
1056 | | - | |
1057 | | - | |
1058 | | - | |
1059 | | - | |
1060 | | - | |
1061 | | - | |
1062 | | - | |
1063 | | - | |
1064 | | - | |
1065 | | - | |
1066 | | - | |
1067 | | - | |
1068 | | - | |
1069 | | - | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
1070 | 1062 | | |
1071 | 1063 | | |
1072 | 1064 | | |
| |||
0 commit comments