imperugo / imperugo/StackExchange.Redis.Extensions

Avoid unnecessary allocations in `ParseInfo` / `ParseCategorizedInfo` in `RedisDatabase`

Open
#669 2 comments 0 reactions 1 assignee View on GitHub

@LeaFrock is already working on this.

Since Aug 8, 2026.

enhancement
Dominant language
C#
Stars
628
Forks
177
PR merge metrics
No merged PRs in 30d

Description

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').

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.