Skip to content

[SPARK-58678][CORE][TESTS] Add OpenHashMapBenchmark - #57881

Closed
dongjoon-hyun wants to merge 4 commits into
apache:masterfrom
dongjoon-hyun:SPARK-58678-2
Closed

[SPARK-58678][CORE][TESTS] Add OpenHashMapBenchmark#57881
dongjoon-hyun wants to merge 4 commits into
apache:masterfrom
dongjoon-hyun:SPARK-58678-2

Conversation

@dongjoon-hyun

@dongjoon-hyun dongjoon-hyun commented Aug 9, 2026

Copy link
Copy Markdown
Member

What changes were proposed in this pull request?

This PR aims to add OpenHashMapBenchmark to measure the performance of
org.apache.spark.util.collection.OpenHashMap against java.util.HashMap in three scenarios
modeled on Spark's real usage:

  • Insert: inserting 1M distinct String keys via update/put
  • Aggregate: 5M changeValue/merge operations over 1M String keys (the typical
    aggregation pattern, e.g. Mode, countByValue)
  • Lookup: looking up 1M String keys in random order

Why are the changes needed?

OpenHashMap claims that it is "about 5X faster than java.util.HashMap".

* but not deletions. This map is about 5X faster than java.util.HashMap, while using much less

However, This claim dates from 2013 (pre-JDK 8), and there has been no benchmark in the repository to
verify it. On modern JDKs, java.util.HashMap has improved significantly. According to this benchmark, Java is much faster for Insert and Lookup.

  • In case of Insert, java.util.HashMap is 4.6X, 5.5X, 6.5X faster in Java 17, 21, and 25, respectively.

  • Note that OpenHashMap still uses about 2.2x less memory than java.util.HashMap for
    String -> Long entries thanks to its specialized primitive value storage. This benchmark
    provides a consistent way to track the trade-off across JDK versions and future improvements.

Does this PR introduce any user-facing change?

No. This is a test-only change.

How was this patch tested?

Manually ran the benchmark:

build/sbt "core/Test/runMain org.apache.spark.util.collection.OpenHashMapBenchmark"

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Fable 5

@dongjoon-hyun

Copy link
Copy Markdown
Member Author

Could you review this PR, @uros-b ?

@uros-b

uros-b commented Aug 9, 2026

Copy link
Copy Markdown
Member

Changes look good @dongjoon-hyun, but it seems that CI didn't run properly?

@dongjoon-hyun

dongjoon-hyun commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

Thank you, @uros-b . CI is running here. So far, there is no issue because this is a new benchmark addition.

Screenshot 2026-08-09 at 13 50 12

@dongjoon-hyun

Copy link
Copy Markdown
Member Author

Let me merge this because the running CI is irrelevant to this PR and the benchmark generation itself is verified when generating the benchmark result already.

dongjoon-hyun added a commit that referenced this pull request Aug 9, 2026
### What changes were proposed in this pull request?

This PR aims to add `OpenHashMapBenchmark` to measure the performance of
`org.apache.spark.util.collection.OpenHashMap` against `java.util.HashMap` in three scenarios
modeled on Spark's real usage:

- **Insert**: inserting 1M distinct String keys via `update`/`put`
- **Aggregate**: 5M `changeValue`/`merge` operations over 1M String keys (the typical
  aggregation pattern, e.g. `Mode`, `countByValue`)
- **Lookup**: looking up 1M String keys in random order

### Why are the changes needed?

`OpenHashMap` claims that it is "about 5X faster than java.util.HashMap".

https://github.com/apache/spark/blob/8645e2c08929bbc1ef2ef66b442f525814f92220/core/src/main/scala/org/apache/spark/util/collection/OpenHashMap.scala#L24

However, This claim dates from 2013 (pre-JDK 8), and there has been no benchmark in the repository to
verify it. On modern JDKs, `java.util.HashMap` has improved significantly. According to this benchmark, Java is much faster for **Insert** and **Lookup**.

- In case of `Insert`, `java.util.HashMap` is 4.6X, 5.5X, 6.5X faster in Java 17, 21, and 25, respectively.

- Note that `OpenHashMap` still uses about 2.2x less memory than `java.util.HashMap` for
`String -> Long` entries thanks to its specialized primitive value storage. This benchmark
provides a consistent way to track the trade-off across JDK versions and future improvements.

### Does this PR introduce _any_ user-facing change?

No. This is a test-only change.

### How was this patch tested?

Manually ran the benchmark:

```
build/sbt "core/Test/runMain org.apache.spark.util.collection.OpenHashMapBenchmark"
```

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Fable 5

Closes #57881 from dongjoon-hyun/SPARK-58678-2.

Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
(cherry picked from commit 9a20f8b)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
dongjoon-hyun added a commit that referenced this pull request Aug 9, 2026
### What changes were proposed in this pull request?

This PR aims to add `OpenHashMapBenchmark` to measure the performance of
`org.apache.spark.util.collection.OpenHashMap` against `java.util.HashMap` in three scenarios
modeled on Spark's real usage:

- **Insert**: inserting 1M distinct String keys via `update`/`put`
- **Aggregate**: 5M `changeValue`/`merge` operations over 1M String keys (the typical
  aggregation pattern, e.g. `Mode`, `countByValue`)
- **Lookup**: looking up 1M String keys in random order

### Why are the changes needed?

`OpenHashMap` claims that it is "about 5X faster than java.util.HashMap".

https://github.com/apache/spark/blob/8645e2c08929bbc1ef2ef66b442f525814f92220/core/src/main/scala/org/apache/spark/util/collection/OpenHashMap.scala#L24

However, This claim dates from 2013 (pre-JDK 8), and there has been no benchmark in the repository to
verify it. On modern JDKs, `java.util.HashMap` has improved significantly. According to this benchmark, Java is much faster for **Insert** and **Lookup**.

- In case of `Insert`, `java.util.HashMap` is 4.6X, 5.5X, 6.5X faster in Java 17, 21, and 25, respectively.

- Note that `OpenHashMap` still uses about 2.2x less memory than `java.util.HashMap` for
`String -> Long` entries thanks to its specialized primitive value storage. This benchmark
provides a consistent way to track the trade-off across JDK versions and future improvements.

### Does this PR introduce _any_ user-facing change?

No. This is a test-only change.

### How was this patch tested?

Manually ran the benchmark:

```
build/sbt "core/Test/runMain org.apache.spark.util.collection.OpenHashMapBenchmark"
```

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Fable 5

Closes #57881 from dongjoon-hyun/SPARK-58678-2.

Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
(cherry picked from commit 9a20f8b)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
dongjoon-hyun added a commit that referenced this pull request Aug 9, 2026
### What changes were proposed in this pull request?

This PR aims to add `OpenHashMapBenchmark` to measure the performance of
`org.apache.spark.util.collection.OpenHashMap` against `java.util.HashMap` in three scenarios
modeled on Spark's real usage:

- **Insert**: inserting 1M distinct String keys via `update`/`put`
- **Aggregate**: 5M `changeValue`/`merge` operations over 1M String keys (the typical
  aggregation pattern, e.g. `Mode`, `countByValue`)
- **Lookup**: looking up 1M String keys in random order

### Why are the changes needed?

`OpenHashMap` claims that it is "about 5X faster than java.util.HashMap".

https://github.com/apache/spark/blob/8645e2c08929bbc1ef2ef66b442f525814f92220/core/src/main/scala/org/apache/spark/util/collection/OpenHashMap.scala#L24

However, This claim dates from 2013 (pre-JDK 8), and there has been no benchmark in the repository to
verify it. On modern JDKs, `java.util.HashMap` has improved significantly. According to this benchmark, Java is much faster for **Insert** and **Lookup**.

- In case of `Insert`, `java.util.HashMap` is 4.6X, 5.5X, 6.5X faster in Java 17, 21, and 25, respectively.

- Note that `OpenHashMap` still uses about 2.2x less memory than `java.util.HashMap` for
`String -> Long` entries thanks to its specialized primitive value storage. This benchmark
provides a consistent way to track the trade-off across JDK versions and future improvements.

### Does this PR introduce _any_ user-facing change?

No. This is a test-only change.

### How was this patch tested?

Manually ran the benchmark:

```
build/sbt "core/Test/runMain org.apache.spark.util.collection.OpenHashMapBenchmark"
```

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Fable 5

Closes #57881 from dongjoon-hyun/SPARK-58678-2.

Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
(cherry picked from commit 9a20f8b)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
@dongjoon-hyun

Copy link
Copy Markdown
Member Author

Merge Summary:

Posted by merge_spark_pr.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants