Skip to content

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

@aautumn725

Description

@aautumn725

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions