Skip to content

Avoid unnecessary allocations in ParseInfo / ParseCategorizedInfo in RedisDatabase #669

Description

@LeaFrock

Observations

  • ParseCategorizedInfo allocates a List<InfoDetail>, only to immediately materialize it into an InfoDetail[].
  • ParseInfo then further projects that array into a Dictionary<string, string>.
  • EnumerateLines is currently an extension method, but is only used by this parsing path.

Proposal

  1. Remove the EnumerateLines extension method and move its logic into InfoDetail.
  2. Add an internal static factory method such as:
    internal static List<InfoDetail> Parse(ReadOnlySpan<char> info)
  3. Allow callers to project directly from the List<InfoDetail>:
    • Into an array (InfoDetail[]) where needed
    • Or into a Dictionary<string, string> for ParseInfo

This would:

  • Eliminate one intermediate array allocation
  • Keep parsing logic co-located with InfoDetail
  • Reduce public surface area (even if just internal)
  • Make allocation patterns clearer and easier to reason about

If desired, we could also consider a Dictionary-backed fast-path once the list is built, but even the structural cleanup alone seems worthwhile.

I want to handle this after #664 gets merged when the SpanExtensions.cs can be deleted then.

More...

  • Would it be better if InfoDetail becomes a read-only struct?
  • Add Task<InfoDetail[]> GetInfoSectionAsync(string section) as Redis supports INFO [section], for example, redis.call('INFO', 'memory').

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions