Skip to content

MINOR: Optimize RemoteLogManager#buildFilteredLeaderEpochMap #20205

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

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

majialoong
Copy link
Contributor

@majialoong majialoong commented Jul 20, 2025

Optimize RemoteLogManager#buildFilteredLeaderEpochMap .

In the original method, there is no need to count the epochs without messages(epochsWithNoMessages) first and then remove them. We can directly calculate and get the results.

Use JMH test :

@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Thread)
public class LeaderEpochMapBenchmark {

    @Param({"1000", "10000", "100000"})
    private int mapSize;

    NavigableMap<Integer, Long> testMap;

    @Setup
    public void setup() {
        testMap = new TreeMap<>();
        for (int i = 0; i < mapSize; i++) {
            /**
             * 0,0
             * 1,0
             * 2,1
             * 3,1
             * ...
             */
            testMap.put(i, (long) (i / 2));
        }
    }

    @Benchmark
    public NavigableMap<Integer, Long> testOriginal() {
        // before optimize (make method public)
        return RemoteLogManager.buildFilteredLeaderEpochMap(testMap);
    }

    @Benchmark
    public NavigableMap<Integer, Long> testOptimized() {
        // after optimize (make method public)
        return RemoteLogManager.buildFilteredLeaderEpochMap2(testMap);
    }
}

Command :
./jmh-benchmarks/jmh.sh LeaderEpochMapBenchmark

Result :
image

@github-actions github-actions bot added triage PRs from the community storage Pull requests that target the storage module tiered-storage Related to the Tiered Storage feature small Small PRs labels Jul 20, 2025
@majialoong
Copy link
Contributor Author

majialoong commented Jul 21, 2025

Hello @chia7712 @kamalcph @frankvicky , If have chance, please take a look this RP, thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
small Small PRs storage Pull requests that target the storage module tiered-storage Related to the Tiered Storage feature triage PRs from the community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant