Repository navigation
Commit dffa1d5
committed
refactor(speculation): drop snapshot validation from bestfirst
## Summary
### Why?
`Generate` re-validated the queue snapshot on every run: seven checks covering empty and duplicate batch IDs, empty, duplicate, and self dependencies, dependencies missing from the snapshot, and unknown dependency states — plus a nil-scorer panic in `New`. Those are properties of a correctly assembled snapshot, established wherever the snapshot is built, so checking them again on the hot path of every run spreads one contract across two places and buys nothing a well-formed snapshot could ever trip. They were also the bulk of `Generate`'s branching.
The scorer range check was different in kind: a score arrives from an injected extension, so no earlier stage can vet it. But sinking the whole run on one bad number is the wrong response when a default will do.
### What?
Snapshot validation is gone. The `Generator` interface doc and the best-first RFC now state the well-formedness rules as a caller precondition — a generator may assume them, and a malformed snapshot yields undefined candidates rather than an error. Nothing consumes the generator yet, so whoever assembles the snapshot will own the check.
One behavior worth flagging for reviewers: a head that repeats a dependency was previously rejected and now produces paths that assume the same batch both succeeds and fails. That is undefined input under the new contract, but it fails quietly rather than loudly.
A score outside `[0, 1]`, or `NaN`, is now replaced with a default of 0.95 rather than rejected. The default is optimistic on purpose: a dependency nobody could estimate keeps its head's preferred path near the front instead of being buried. Both comparisons in `asProbability` are false for `NaN`, so it needs no separate case.
`Generate` is now three linear steps — index, `speculatingHeads`, `score` — and seeding the global heap appends and heapifies once. Previously `heap.Init` ran on an empty slice and each head was pushed individually, costing a sift and an interface boxing per head; building the slice first is linear. `slices.Sorted(maps.Keys(...))` replaces the collect-then-sort loop, and `slices.Clone` replaces three `make`+`copy` pairs.
Net 143 lines removed, 80 added.
## Test Plan
✅ `go test ./submitqueue/extension/speculation/...`
✅ `go vet ./submitqueue/extension/speculation/...`
✅ `gofmt -l submitqueue/extension/speculation/` — clean
The malformed-snapshot table test is removed. The score-range test now asserts the default is applied and both of the head's paths still come out, ranked as the default and its complement, rather than asserting an error.1 parent 63f4f56 commit dffa1d5
4 files changed
Lines changed: 80 additions & 143 deletions
File tree
- doc/rfc/submitqueue
- submitqueue/extension/speculation/generator
- bestfirst
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | 28 | | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | 50 | | |
54 | 51 | | |
55 | 52 | | |
56 | | - | |
57 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
58 | 56 | | |
59 | 57 | | |
60 | 58 | | |
61 | 59 | | |
62 | 60 | | |
63 | 61 | | |
64 | 62 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | 63 | | |
72 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
73 | 85 | | |
74 | | - | |
75 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
76 | 91 | | |
77 | 92 | | |
78 | 93 | | |
79 | 94 | | |
80 | 95 | | |
81 | | - | |
82 | | - | |
83 | 96 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
| 97 | + | |
| 98 | + | |
104 | 99 | | |
105 | 100 | | |
106 | 101 | | |
| 102 | + | |
| 103 | + | |
107 | 104 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
116 | 108 | | |
117 | 109 | | |
118 | 110 | | |
| |||
122 | 114 | | |
123 | 115 | | |
124 | 116 | | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
| 117 | + | |
129 | 118 | | |
| 119 | + | |
| 120 | + | |
130 | 121 | | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
139 | 134 | | |
140 | | - | |
| 135 | + | |
141 | 136 | | |
142 | 137 | | |
143 | 138 | | |
| |||
282 | 277 | | |
283 | 278 | | |
284 | 279 | | |
285 | | - | |
286 | | - | |
| 280 | + | |
287 | 281 | | |
288 | 282 | | |
289 | 283 | | |
| |||
301 | 295 | | |
302 | 296 | | |
303 | 297 | | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
| 298 | + | |
308 | 299 | | |
309 | 300 | | |
310 | 301 | | |
311 | | - | |
312 | | - | |
| 302 | + | |
313 | 303 | | |
314 | 304 | | |
315 | 305 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
392 | 392 | | |
393 | 393 | | |
394 | 394 | | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | 395 | | |
461 | 396 | | |
462 | 397 | | |
| |||
841 | 776 | | |
842 | 777 | | |
843 | 778 | | |
844 | | - | |
| 779 | + | |
845 | 780 | | |
846 | | - | |
847 | | - | |
| 781 | + | |
| 782 | + | |
848 | 783 | | |
849 | | - | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
850 | 787 | | |
851 | 788 | | |
852 | 789 | | |
| |||
855 | 792 | | |
856 | 793 | | |
857 | 794 | | |
| 795 | + | |
858 | 796 | | |
859 | 797 | | |
860 | 798 | | |
| |||
865 | 803 | | |
866 | 804 | | |
867 | 805 | | |
868 | | - | |
869 | | - | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
870 | 816 | | |
871 | 817 | | |
872 | 818 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
0 commit comments