Skip to content

Large wordlists peak at ~150 B/entry: raw lines, visited map, per-source sets #248

Closed

Description

@TMHSDigital

Summary

Loading a large wordlist peaks at about 150 bytes per entry and takes several seconds before the first query. The memory comes from several full copies of the list: raw lines, the Prepare index, the dispatcher's visited map, and a set rebuilt for each passive source and for -permute.

Where

  • internal/wordlist/reader.go:93-124 (ReadLinesFrom keeps every raw line in a []string)
  • internal/wordlist/reader.go:146-168 (Prepare builds a map[string]int plus entries and counts)
  • internal/scan/dispatcher.go:52, :136-150: a visited map sized to the whole list, built per target and per pass
  • main_ct.go:84-117: withCTEntries builds a full have map on each call, and withCTSeeds copies the seeds map
  • main_permute.go:73-81: permutationCandidates builds another full skip map
  • main_session.go:395-402, main_session.go:636-651

Details

Measured with the built binary on a synthetic 5M-line wordlist (54 MB) and -simulate -max-queries 1: 763 MB peak working set, 6.8 s before the first query finished.

  • The visited map alone costs about 218 MB and 1.3 s at 5M entries.
  • In non-recursive scans (the default) it never finds a duplicate: at depth 1 the key is the entry itself, and every caller already deduplicates Entries (Prepare, withCTEntries, wordlist.Build).
  • Each full-list map[string]bool (one per passive source, one for -axfr, one for -permute) costs about 1.2 s and 130 MB at 5M entries.

Impact

Lists of 9-10M lines (common public DNS wordlists) need about 1.5 GB and more than 10 s of startup per target. That risks OOM in 1-2 GB containers and CI runners, and -dL repeats the cost for every target.

Suggested fix

  1. Allocate and consult visited only when cfg.Recursive is set. Document that Entries must be unique.
  2. Normalize and deduplicate while streaming the file, so the raw lines slice is never held. Make the Prepare index the only set.
  3. Build the entry set once per target, or expose Prepared's index, and reuse it across sources, AXFR and permute.

Acceptance criteria

  • Peak RSS for a 5M-line list with -max-queries 1 drops by at least 40%, as measured by a benchmark or a documented manual run.
  • No change in candidate order or deduplication results (existing wordlist and dispatcher tests pass).

Getting started

  • Relevant files: listed above
  • How to run tests: go test ./internal/wordlist/ ./internal/scan/ .; benchmarks with go test -run=^$ -bench=. ./internal/wordlist/
  • Related docs: docs/ARCHITECTURE.md

Related: #56, #49


Filed by repo-audit/full-audit at 3f671b2. Severity: medium. Effort: M. audit-key: performance|internal/wordlist/reader.go|load-memory

Activity

  1. added
    help wanted
    performance
    severity: medium
    on Nov 14, 2026
  2. TMHSDigital commented on Nov 14, 2026

    @TMHSDigital
    OwnerAuthor

    Partial fix in 09b2475: all three steps from the issue are done.

    • -w files are normalized while they are read (wordlist.Preparer, EachLine), so the raw lines are never held.
    • A non-recursive scan keeps no dispatcher visited set.
    • Passive sources and AXFR add to one candidates set per target.

    Measured on a 5M-line list with -simulate -max-queries 1 (peak working set, 3 runs each):

    peak MB time
    before (3f671b2-era code at HEAD~1) 706, 742, 767 2.6–3.1 s
    after 576, 559, 559 2.7–3.2 s

    That is about 23% lower, short of the 40% acceptance criterion, so this stays open. The peak now comes from Prepare itself: its dedupe index (map[string]int, one entry per unique label) coexists with the entries and counts slices while the list is read. Options for the rest:

    • a map[string]int32 index and int32 counts, worth roughly 10%;
    • dedupe without a map: sort a copy of the entries and their indices, then drop repeats. This is slower, but it removes the map's per-entry overhead.
  3. TMHSDigital commented on Nov 14, 2026

    @TMHSDigital
    OwnerAuthor

    Fixed in dddb5eb, which takes the remaining step after 09b2475. Prepare's map[string]int dedupe index is now an open-addressing table of uint32 positions that compares against the entries already held, and the per-entry counts are uint32.

    Peak working set of the built binary on a 5M-line list with -simulate -max-queries 1 (Windows, polled):

    peak MB time
    HEAD before (5fdee9a) 592, 605, 590 2.9-3.0 s
    after 366, 335, 350, 417 2.3-2.7 s

    That is about 38% below the previous HEAD and about 50% below the ~740 MB in the original report, so the 40% criterion is met. BenchmarkBuild1M also went from ~520 ms / 241 MB per op to ~380 ms / 126 MB per op.

    Order and dedupe results are unchanged: the existing wordlist and dispatcher tests pass, and the new TestPrepareIndexAcrossGrowth checks the index against the reference build across ~8 table doublings, with case-variant repeats.

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

    help wantedperformanceseverity: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions