Back to Trufflehog

Iterative Decoding Performance

docs/iterative_decoding_performance.md

3.94.32.7 KB
Original Source

Iterative Decoding Performance

Performance characteristics of the --max-decode-depth feature, which enables chained decoding (e.g., base64 inside UTF-16, double-encoded base64).

How it works

At depth 0, all decoders run on the original chunk (identical to pre-existing behavior). When a decoder produces new output, that output is fed back through all decoders at the next depth level. The loop exits early when no decoder produces new data, so unused depth levels are effectively free.

The PLAIN (UTF-8) decoder is skipped at depth > 0 since it's a passthrough that never transforms data produced by other decoders (their output is already valid UTF-8/ASCII).

Filesystem scan benchmark

Scanned the trufflehog repository (~4,500 files) with --no-verification and --concurrency=1 for deterministic comparison.

DepthWall timeUnique resultsDelta vs depth=1
18.05s924
28.18s927+3, +1.6%
38.09s928+4, +0.5%
58.19s928+4, +1.7%
108.35s932+8, +3.7%

Results converge by depth 3. Depths 4–5 produce no additional decoded data in this corpus, so they add only a single len() == 0 check per chunk per extra depth level.

The small unique-result variance at depth 10 is from pre-existing nondeterminism in the concurrent detector workers' dedup ordering, not from the decoding itself.

Per-decoder microbenchmarks

Individual decoder cost is unchanged by this feature (decoders are not modified). For reference, base64 decoder latency on random data:

Input sizeLatency/opAllocs
100 B~250 ns96 B / 2
1 KB~2.25 µs96 B / 2
10 KB~44 ns96 B / 2

The 10 KB case is fast because random bytes rarely form valid base64 substrings (the 20-character minimum threshold is never met), so the decoder exits after a single O(n) character scan.

Memory overhead

Each depth level that produces new decoded data stores one copy of the output (typically smaller than the input, since base64 decoding shrinks by ~25%). A seen list (slice of byte slices) prevents reprocessing identical data. At depth 5 on a typical chunk, this list has 0–3 entries. No hashing or maps are used.

Choosing a depth

DepthUse case
1Legacy behavior, no chaining
2Covers base64-in-base64, base64-in-UTF-16, base64-in-escaped-unicode
5Default. Handles deeply nested configs with no measurable cost over depth 2