Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix FrequencyVectorBuilder performance issue by range count. #1832

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class FrequencyVectorBuilder(
*/
private val primaryRange: IntRange

private val primaryRangeCount: Int

/**
* For a wrapping VidSamplingInterval this is the part of the range than spans [0, width-start)
*/
Expand All @@ -114,6 +116,7 @@ class FrequencyVectorBuilder(
val globalEndIndex =
(populationSize * (vidSamplingInterval.start + vidSamplingInterval.width)).toInt() - 1
primaryRange = globalStartIndex..minOf(globalEndIndex, populationSize - 1)
primaryRangeCount = primaryRange.count()
wrappedRange =
if (globalEndIndex >= populationSize) {
0..(globalEndIndex - populationSize)
Expand All @@ -131,7 +134,7 @@ class FrequencyVectorBuilder(

init {
// Initialize the frequency vector
val frequencyVectorSize = primaryRange.count() + wrappedRange.count()
val frequencyVectorSize = primaryRangeCount + wrappedRange.count()
frequencyData = IntArray(frequencyVectorSize)
}

Expand Down Expand Up @@ -197,7 +200,7 @@ class FrequencyVectorBuilder(
if (globalIndex in primaryRange) {
globalIndex - primaryRange.first
} else {
primaryRange.count() + globalIndex
primaryRangeCount + globalIndex
}
frequencyData[localIndex] = minOf(frequencyData[localIndex] + amount, maxFrequency)
}
Expand Down