-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
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