Skip to content

Vectorize Hashing in FlatGroupByHash#19302

Merged
pettyjamesm merged 3 commits intotrinodb:masterfrom
pettyjamesm:vectorize-flatgroupbyhash-hashing
Oct 19, 2023
Merged

Vectorize Hashing in FlatGroupByHash#19302
pettyjamesm merged 3 commits intotrinodb:masterfrom
pettyjamesm:vectorize-flatgroupbyhash-hashing

Conversation

@pettyjamesm
Copy link
Copy Markdown
Member

@pettyjamesm pettyjamesm commented Oct 6, 2023

Description

Implements column-wise hash calculations in FlatHashCompiler and changes FlatGroupByHash to use it to implement a batched approach to first computing a range of position hashes and then attempting to insert those positions using the hashes that were precomputed.

By calculating position hashes in a columnar traversal, we can avoid repeated expensive bounds checking per access, allow the JIT to emit more efficient unrolled loops, and access the memory in a way that friendlier and more predictable for CPU caches.

Additionally, when attempting to insert the positions into the FlatGroupByHash after precomputing the hash code we can start loading the relevant portition of the hash table into memory sooner since we aren't intermixing computing the hash with the memory accesses.

Since re-hashing is still performed row-at-a-time, the performance improvement is much more significant when the number of groups is small and when the number of columns in the hash calculation are larger.

BenchmarkGroupByHash.addPages results generally improve between 5-50% depending on the scenario:

Release notes

(x) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text:

@cla-bot cla-bot bot added the cla-signed label Oct 6, 2023
@pettyjamesm pettyjamesm requested a review from dain October 6, 2023 19:28
@wendigo
Copy link
Copy Markdown
Contributor

wendigo commented Oct 6, 2023

test-other-modules failure is unrelated. I just fixed that in master. Sorry :)

@pettyjamesm pettyjamesm force-pushed the vectorize-flatgroupbyhash-hashing branch from 09ac658 to 68f7df6 Compare October 6, 2023 20:16
@pettyjamesm
Copy link
Copy Markdown
Member Author

test-other-modules failure is unrelated. I just fixed that in master. Sorry :)

No worries, thanks for the heads up- just rebased to pick up the fix.

@pettyjamesm pettyjamesm marked this pull request as ready for review October 6, 2023 22:24
@starburstdata-automation
Copy link
Copy Markdown

starburstdata-automation commented Oct 7, 2023

Started benchmark workflow for this PR.

Benchmark finished with status: failure
Status message: Failed benchmarks.
❌ Benchmark workflow failed.

@pettyjamesm pettyjamesm force-pushed the vectorize-flatgroupbyhash-hashing branch from 3bbddf6 to 9fd7533 Compare October 9, 2023 15:56
@starburstdata-automation
Copy link
Copy Markdown

starburstdata-automation commented Oct 9, 2023

Started benchmark workflow for this PR.

Benchmark finished with status: success
Status message: No baseline found.
report.zip

Benchmark Summary:

Top 5 duration differences

Left Environment Right Environment Benchmark Name Query Name Diff Diff Pct Left Mean Left Mean Err Right Mean Right Mean Err
hp-base-oss-6_r6g_8xlarge-f92b119a0e-hive_sf1000_parquet_part-s3452 vectorize-flatgroupbyhash-hashing-oss-6_r6g_8xlarge-9fd75333be-hive_sf1000_parquet_part-p18 presto/tpch q01 00:00:01.295833 ▲10.18 00:00:11.438 ±00:00:00.754284 (0.07%) 00:00:12.733833 ±00:00:01.522639 (0.12%)
hp-base-oss-6_r6g_8xlarge-f92b119a0e-hive_sf1000_parquet_part-s3452 vectorize-flatgroupbyhash-hashing-oss-6_r6g_8xlarge-9fd75333be-hive_sf1000_parquet_part-p18 presto/tpch q02 00:00:00.559333 ▲5.29 00:00:10.024 ±00:00:00.337022 (0.03%) 00:00:10.583333 ±00:00:01.334157 (0.13%)
hp-base-oss-6_r6g_8xlarge-f92b119a0e-hive_sf1000_parquet_part-s3452 vectorize-flatgroupbyhash-hashing-oss-6_r6g_8xlarge-9fd75333be-hive_sf1000_parquet_part-p18 presto/tpch q17 -00:00:02.282833 ▼-5.36 00:00:42.582167 ±00:00:01.506255 (0.04%) 00:00:40.299333 ±00:00:00.873434 (0.02%)
hp-base-oss-6_r6g_8xlarge-f92b119a0e-hive_sf1000_parquet_part-s3452 vectorize-flatgroupbyhash-hashing-oss-6_r6g_8xlarge-9fd75333be-hive_sf1000_parquet_part-p18 presto/tpch q18 -00:00:03.299 ▼-6.21 00:00:53.157 ±00:00:02.329143 (0.04%) 00:00:49.858 ±00:00:01.509759 (0.03%)
hp-base-oss-6_r6g_8xlarge-f92b119a0e-hive_sf1000_parquet_part-s3452 vectorize-flatgroupbyhash-hashing-oss-6_r6g_8xlarge-9fd75333be-hive_sf1000_parquet_part-p18 presto/tpch q07 -00:00:00.818 ▼-6.90 00:00:11.862 ±00:00:00.401573 (0.03%) 00:00:11.044 ±00:00:00.440955 (0.04%)

@pettyjamesm pettyjamesm force-pushed the vectorize-flatgroupbyhash-hashing branch from 9fd7533 to 8df5f3a Compare October 11, 2023 19:37
Copy link
Copy Markdown
Member

@martint martint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Squash the first three commits, as they are all essentially incremental parts of the same change.

@martint martint mentioned this pull request Oct 18, 2023
19 tasks
Implements column-wise hash calculations in FlatHashCompiler and changes
FlatGroupByHash to use it to implement a batched approach to first
computing a range of position hashes and then attempting to insert those
positions using the hashes that were precomputed.

By calculating position hashes in a columnar tarversal path, we can
avoid repeated expensive bounds checking and allow the JIT to unroll
loops into much more efficient forms.

Additionally, when attempting to insert the positions into the
FlatGroupByHash after precomputing the hash code we can start loading
the relevant portition of the hash table into memory sooner since we
aren't intermixing computing the hash with the memory accesses.
@pettyjamesm pettyjamesm force-pushed the vectorize-flatgroupbyhash-hashing branch from 8df5f3a to 1a75e64 Compare October 19, 2023 15:47
@pettyjamesm pettyjamesm merged commit 1ea28e4 into trinodb:master Oct 19, 2023
@pettyjamesm pettyjamesm deleted the vectorize-flatgroupbyhash-hashing branch October 19, 2023 20:15
@github-actions github-actions bot added this to the 430 milestone Oct 19, 2023
@mosabua
Copy link
Copy Markdown
Member

mosabua commented Oct 21, 2023

Please note that we added a release notes entry for the performance improvement @pettyjamesm .. for future reference and as an example.

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

Development

Successfully merging this pull request may close these issues.

5 participants