wireshark-0001 + julia-0002: QUIC streams O(S²) 499x; reinfer BFS O(V²) 225x; count 618→620

This commit is contained in:
russell@unturf.com 2026-03-29 14:24:54 -04:00
parent a8b806626f
commit 518eb4943e
4 changed files with 343 additions and 0 deletions

View file

@ -0,0 +1,54 @@
## Classification
| Field | Value |
|-------------|-------|
| CWE | CWE-407 Inefficient Algorithmic Complexity |
| Severity | MEDIUM |
| Component | `Compiler/src/reinfer.jl:432` |
| Function | (method order determination — morespecific BFS) |
| Hot path | Method dispatch ordering — called during type inference for every ambiguous method pair |
| Status | PATCHED (unit test PASS) |
## Defect
Method interference graph BFS uses `visited = Method[]` (Array) with `method3 in visited`
for cycle prevention. `in` on a Julia Vector/Array is O(V) linear scan:
```julia
visited = Method[] # Array — O(V) membership
push!(visited, method2)
workqueue = Method[method2]
while !isempty(workqueue)
current = pop!(workqueue)
for k = 1:length(interferences)
method3 = interferences[k]::Method
method3 in visited && continue # O(V) per check — CWE-407
push!(visited, method3)
push!(workqueue, method3)
end
end
```
With V methods reachable in the interference graph, total membership checks: O(V²).
Called during type inference for every ambiguous method pair resolution.
## Fix
```julia
visited = Set{Method}() # O(1) membership
push!(visited, method2)
workqueue = Method[method2]
while !isempty(workqueue)
current = pop!(workqueue)
for k = 1:length(interferences)
method3 = interferences[k]::Method
method3 in visited && continue # O(1) hash lookup
push!(visited, method3)
push!(workqueue, method3)
end
end
```
Speedup: O(V²) → O(V) — ~250× at V=500 (62,500 → 500 checks).