Skip to content

-hosts with -dL walks every host name once per target: O(names x targets) #465

Done

Description

@TMHSDigital

Summary

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 } ...)
  • internal/cli/session.go:749, internal/cli/prefetch.go:89, internal/cli/session.go:509, internal/cli/dryrun.go:95 (callers)

Impact

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).

Getting started

  • Relevant files: internal/wordlist/reader.go, internal/wordlist/reader_test.go
  • How to run tests: go test ./internal/wordlist

Filed by repo-audit/full-audit at a45b999. Severity: medium. Effort: S. audit-key: performance|internal/wordlist/reader.go|Prepared.under

Activity

  1. added
    good first issue
    performance
    severity: medium
    on Nov 29, 2026
  2. TMHSDigital commented on Nov 29, 2026

    @TMHSDigital
    OwnerAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueperformanceseverity: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions