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
- Remove the
EnumerateLines extension method and move its logic into InfoDetail.
- 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> 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').
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
EnumerateLinesextension method and move its logic intoInfoDetail.List<InfoDetail>:InfoDetail[]) where neededDictionary<string, string>forParseInfoThis would:
InfoDetailinternal)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.cscan be deleted then.More...
InfoDetailbecomes a read-only struct?Task<InfoDetail[]> GetInfoSectionAsync(string section)as Redis supportsINFO [section], for example,redis.call('INFO', 'memory').