HistogramBase.GetValueAtPercentile — Double-Loop When Flat Array Index Is Available
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 55/100
- Issue type
- Refactor
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- csharp
- Domain
- performance
Research direction
Start in HistogramBase.cs at GetValueAtPercentile and inspect how LongHistogram stores its counts, including CountsArrayLength, GetCountAtIndex, and ValueFromIndex. Compare the existing nested scan with the proposed flat traversal; done means percentile lookup preserves the current result while avoiding the nested index mapping.
Written by the indexing model from the issue text.
Description
File: HistogramBase.cs
The percentile lookup iterates nested i / j loops over BucketCount × SubBucketCount. Since CountsArrayIndex(bucketIndex, subBucketIndex) maps this to a flat array, and the counts array is already flat in LongHistogram, the entire scan can be done as a single flat loop:
public long GetValueAtPercentile(double percentile) { var countAtPercentile = Math.Max( (long)((Math.Min(percentile, 100.0) / 100.0 * TotalCount) + 0.5), 1);long runningCount = 0; for (int i = 0; i < CountsArrayLength; i++) { runningCount += GetCountAtIndex(i); if (runningCount >= countAtPercentile) return HighestEquivalentValue(ValueFromIndex(i)); } throw new ArgumentOutOfRangeException(...);
}
The nested loop computes GetCountAt(i, j) → GetCountAtIndex(CountsArrayIndex(i, j)) anyway — the flat version eliminates the CountsArrayIndex call per iteration and improves cache locality by accessing memory sequentially.
- Dominant language
- C#
- Stars
- 185
- Forks
- 31
- PR merge metrics
- No merged PRs in 30d
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing 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.
More from HdrHistogram/HdrHistogram.NET
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
HdrHistogram/HdrHistogram.NET#167 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
HdrHistogram/HdrHistogram.NET#166 ·
-
WriterReaderPhaser.FlipPhase - Task.Yield().GetAwaiter().GetResult() is a Thread Pool Anti-PatternOpenagent enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
HdrHistogram/HdrHistogram.NET#144 ·
-
agent enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
HdrHistogram/HdrHistogram.NET#142 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
HdrHistogram/HdrHistogram.NET#156 ·
All issues in HdrHistogram/HdrHistogram.NET
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
MicrosoftLearning/PL-400_Microsoft-Power-Platform-Developer#231 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
joinrpg/joinrpg-net#5313 ·
Maintainers usually reply within 1 day
-
[12.x] FixIncorrectOwnerIdRelationships can delete legitimate library roots when UserView shares the same pathPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 1 day