apache / apache/beam

Use StringBuilder to stringKey of StateNamespace instead of String.format

Open
#18,135 0 comments 0 reactions 0 assignees View on GitHub
core improvement P3 runners
Dominant language
Java
Stars
8.7k
Forks
4.7k
Avg merge
1d 20h
Merged PRs (30d)
196

Description

In Flink Runner, each State visit will call the namespace stringKey once. Since stringKey uses String.format to deal with, the impact on performance is relatively large.
Some extreme cases, stringKey performance consumption of up to 2%.
Here is a test on StringBuilder and String.format:
```

public static void main(String[] args) throws Exception {
String[] strs = new String[1000_000];

for (int i = 0; i < strs.length; i++) {
strs[i] = getRandomString(10);
}
{
long
start = System.nanoTime();
for (int i = 0; i < strs.length; i++) {
strs[i] = testFormat(strs[i]);

}
System.out.println("testStringFormat: " + ((System.nanoTime() - start)/1000_000) + "ms");

}
{
long start = System.nanoTime();
for (int i = 0; i < strs.length; i++) {

strs[i] = testStringBuild(strs[i]);
}
System.out.println("testStringBuilder: " + ((System.nanoTime()
- start)/1000_000) + "ms");
}
}

```

testStringFormat: 2312ms
testStringBuilder: 266ms

Imported from Jira [BEAM-1587](https://issues.apache.org/jira/browse/BEAM-1587). Original Jira may contain additional context.
Reported by: lzljs3620320.

Contributor guide

Open the contributing guide

Research direction

Search the Beam codebase for StateNamespace.stringKey and inspect its current String.format implementation and callers in the Flink Runner. Preserve the existing string-key output while replacing the formatting approach, then run the relevant Runner tests or the project test suite to verify behavior and performance.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
performance
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.