You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by "Jingsong Lee (JIRA)" <ji...@apache.org> on 2017/03/02 03:14:46 UTC

[jira] [Updated] (BEAM-1587) Use StringBuilder to stringKey of StateNamespace instead of String.format

     [ https://issues.apache.org/jira/browse/BEAM-1587?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jingsong Lee updated BEAM-1587:
-------------------------------
    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:
{code}
  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");
    }
  }
{code}
testStringFormat: 2312ms
testStringBuilder: 266ms

> Use StringBuilder to stringKey of StateNamespace instead of String.format
> -------------------------------------------------------------------------
>
>                 Key: BEAM-1587
>                 URL: https://issues.apache.org/jira/browse/BEAM-1587
>             Project: Beam
>          Issue Type: Improvement
>          Components: runner-core
>            Reporter: Jingsong Lee
>            Assignee: Kenneth Knowles
>
> 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:
> {code}
>   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");
>     }
>   }
> {code}
> testStringFormat: 2312ms
> testStringBuilder: 266ms



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)