trufflehog icon indicating copy to clipboard operation
trufflehog copied to clipboard

Support string input in FromData to avoid redundant []byte → string conversion

Open aautumn725 opened this issue 2 months ago • 3 comments

Description Currently, the FromData(ctx context.Context, verify bool, data []byte) function accepts a []byte parameter, but the data is immediately converted to a string within the function body. However, in most cases, the caller has already converted the input into a string before calling FromData, leading to a redundant and potentially costly conversion cycle (string → []byte → string).

Preferred Solution Refactor FromData to either accept a string type directly or provide an additional helper method such as FromStringData(...) to avoid unnecessary type conversions.

Example:

FromData(ctx context.Context, verify bool, data string) This change would help reduce GC pressure and CPU usage in high-throughput scenarios where repeated type conversions could accumulate measurable overhead.

Additional Context In Go, converting between []byte and string results in memory allocations. For performance-sensitive code paths, especially when processing large volumes of data or in concurrent environments, minimizing these allocations is beneficial.

References N/A

aautumn725 avatar Aug 07 '25 12:08 aautumn725