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

[SPARK-16699][SQL] Fix performance bug in hash aggregate on long string keys #14337

Closed
wants to merge 1 commit into from

Conversation

ooq
Copy link
Contributor

@ooq ooq commented Jul 24, 2016

What changes were proposed in this pull request?

In the following code in VectorizedHashMapGenerator.scala:

    def hashBytes(b: String): String = {
      val hash = ctx.freshName("hash")
      s"""
         |int $result = 0;
         |for (int i = 0; i < $b.length; i++) {
         |  ${genComputeHash(ctx, s"$b[i]", ByteType, hash)}
         |  $result = ($result ^ (0x9e3779b9)) + $hash + ($result << 6) + ($result >>> 2);
         |}
       """.stripMargin
    }

when b=input.getBytes(), the current 2.0 code results in getBytes() being called n times, n being length of input. getBytes() involves memory copy is thus expensive and causes a performance degradation.
Fix is to evaluate getBytes() before the for loop.

How was this patch tested?

Performance bug, no additional test added.

@ooq
Copy link
Contributor Author

ooq commented Jul 24, 2016

cc @rxin @sameeragarwal

@sameeragarwal
Copy link
Member

LGTM pending jenkins.

@SparkQA
Copy link

SparkQA commented Jul 25, 2016

Test build #62774 has finished for PR 14337 at commit 9102d50.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@rxin
Copy link
Contributor

rxin commented Jul 25, 2016

Merging in master/2.0.

asfgit pushed a commit that referenced this pull request Jul 25, 2016
…ng keys

## What changes were proposed in this pull request?

In the following code in `VectorizedHashMapGenerator.scala`:
```
    def hashBytes(b: String): String = {
      val hash = ctx.freshName("hash")
      s"""
         |int $result = 0;
         |for (int i = 0; i < $b.length; i++) {
         |  ${genComputeHash(ctx, s"$b[i]", ByteType, hash)}
         |  $result = ($result ^ (0x9e3779b9)) + $hash + ($result << 6) + ($result >>> 2);
         |}
       """.stripMargin
    }

```
when b=input.getBytes(), the current 2.0 code results in getBytes() being called n times, n being length of input. getBytes() involves memory copy is thus expensive and causes a performance degradation.
Fix is to evaluate getBytes() before the for loop.

## How was this patch tested?

Performance bug, no additional test added.

Author: Qifan Pu <qifan.pu@gmail.com>

Closes #14337 from ooq/SPARK-16699.
@rxin
Copy link
Contributor

rxin commented Jul 25, 2016

@ooq next time please open a pull request against master branch rather than 2.0. Thanks.

@asfgit asfgit closed this in 468a3c3 Jul 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants