imperugo / imperugo/StackExchange.Redis.Extensions
Avoid unnecessary allocations in `ParseInfo` / `ParseCategorizedInfo` in `RedisDatabase`
Open
@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
ParseCategorizedInfoallocates aList<InfoDetail>, only to immediately materialize it into anInfoDetail[].ParseInfothen further projects that array into aDictionary<string, string>.EnumerateLinesis currently an extension method, but is only used by this parsing path.
Proposal
- Remove the
EnumerateLinesextension method and move its logic intoInfoDetail. - Add an internal static factory method such as:
internal static List<InfoDetail> Parse(ReadOnlySpan<char> info) - Allow callers to project directly from the
List<InfoDetail>:- Into an array (
InfoDetail[]) where needed - Or into a
Dictionary<string, string>forParseInfo
- Into an array (
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
InfoDetailbecomes a read-only struct? - Add
Task<InfoDetail[]> GetInfoSectionAsync(string section)as Redis supportsINFO [section], for example,redis.call('INFO', 'memory').
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.