You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
-hosts with -dL walks every host name once per target: O(names x targets) #465
With -hosts and -dL, selecting each target's names walks the whole host list and recomputes every entry's owner, once per target (twice with the lookahead). Selection is O(names x targets) even though each name belongs to exactly one target.
Where
internal/wordlist/reader.go:175, :203-206 (under: for i, entry := range p.entries { if p.owner(entry) != domain { continue } ...)
One pass of the owner loop over 1M names takes about 31 ms. An org-wide list of 5M names across 5000 -dL roots costs about 2 x 5000 x 155 ms, roughly 26 minutes of single-threaded CPU before and between targets, while the resolver pool is idle. Run time grows quadratically with program size although the query count does not.
Steps to reproduce
subenum -simulate -dL roots.txt -hosts hosts.txt with 5000 roots and 5M names spread under them: most of the run time is between === [i/N] target === lines, with one core pinned.
Suggested fix
In LimitTo (or on the first under call), bucket the entries once by owner, for example map[string][]int32 of indexes into p.entries. under(domain) then walks only its bucket, making the total O(names). Outside() becomes the count of entries with no owner from the same pass.
Acceptance criteria
A benchmark with many targets and names shows selection linear in names.
Existing -hosts tests pass unchanged (same entries, duplicates and skipped counts per target).
Fixed in a10eb6d: LimitTo now buckets entry indexes by owner in one pass (and counts names under no target), so For walks only its own bucket and Outside is O(1). New BenchmarkHostsManyTargets (200k names over 2000 targets, LimitTo plus every For): 8.93 s/op before, 11.4 ms/op after. New TestLimitToBuckets checks per-target entries, duplicates and Outside; the existing TestLimitTo and -hosts CLI tests pass unchanged. Gate (gofmt, vet, golangci-lint v2.15.0, full suite) passes.
Activity
TMHSDigital commentedon Nov 29, 2026
Fixed in a10eb6d: LimitTo now buckets entry indexes by owner in one pass (and counts names under no target), so For walks only its own bucket and Outside is O(1). New BenchmarkHostsManyTargets (200k names over 2000 targets, LimitTo plus every For): 8.93 s/op before, 11.4 ms/op after. New TestLimitToBuckets checks per-target entries, duplicates and Outside; the existing TestLimitTo and -hosts CLI tests pass unchanged. Gate (gofmt, vet, golangci-lint v2.15.0, full suite) passes.