Skip to content

[optimizer] cache the previous hash in TransformCtx #30868

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

Merged
merged 3 commits into from
Dec 19, 2024

Conversation

mgree
Copy link
Contributor

@mgree mgree commented Dec 18, 2024

#30806 adds some metrics on transforms, but the work of hashing is non-trivial on very large queries. We can reduce hashing by half: store the previous hash in TransformCtx. (Using TransformCtx is @ggevay's idea; I was going to do something much more invasive.)

This shows a ~3s speedup on the InsertMultiRow benchmark on my machine (8s -> 5s).

Motivation

Checklist

  • This PR has adequate test coverage / QA involvement has been duly considered. (trigger-ci for additional test/nightly runs)
  • This PR has an associated up-to-date design doc, is a design doc (template), or is sufficiently small to not require a design.
  • If this PR evolves an existing $T ⇔ Proto$T mapping (possibly in a backwards-incompatible way), then it is tagged with a T-proto label.
  • If this PR will require changes to cloud orchestration or tests, there is a companion cloud PR to account for those changes that is tagged with the release-blocker label (example).
  • If this PR includes major user-facing behavior changes, I have pinged the relevant PM to schedule a changelog post.

@mgree mgree requested a review from a team as a code owner December 18, 2024 21:35
@ggevay ggevay self-requested a review December 19, 2024 14:41
Copy link
Contributor

@ggevay ggevay left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@mgree
Copy link
Contributor Author

mgree commented Dec 19, 2024

Running locally, here's the overhead with the soft assert:

NAME                                | TYPE            |      THIS       |      OTHER      |  UNIT  | THRESHOLD  |  Regression?  | 'THIS' is
--------------------------------------------------------------------------------------------------------------------------------------------------------
InsertMultiRow                      | wallclock       |           1.876 |           0.793 |   s    |    10%     |    !!YES!!    | worse:   2.4 TIMES slower
InsertMultiRow                      | memory_mz       |        2126.694 |        2031.326 |   MB   |    20%     |      no       | worse:   4.7% more
InsertMultiRow                      | memory_clusterd |         219.536 |         293.541 |   MB   |    50%     |      no       | better: 25.2% less

NAME                                | TYPE            |      THIS       |      OTHER      |  UNIT  | THRESHOLD  |  Regression?  | 'THIS' is
--------------------------------------------------------------------------------------------------------------------------------------------------------
InsertMultiRow                      | wallclock       |           1.990 |           0.924 |   s    |    10%     |    !!YES!!    | worse:   2.2 TIMES slower
InsertMultiRow                      | memory_mz       |        2055.168 |        1873.016 |   MB   |    20%     |      no       | worse:   9.7% more
InsertMultiRow                      | memory_clusterd |         225.735 |         219.345 |   MB   |    50%     |      no       | worse:   2.9% more

NAME                                | TYPE            |      THIS       |      OTHER      |  UNIT  | THRESHOLD  |  Regression?  | 'THIS' is
--------------------------------------------------------------------------------------------------------------------------------------------------------
InsertMultiRow                      | wallclock       |           2.036 |           0.820 |   s    |    10%     |    !!YES!!    | worse:   2.5 TIMES slower
InsertMultiRow                      | memory_mz       |        1979.828 |        1870.155 |   MB   |    20%     |      no       | worse:   5.9% more
InsertMultiRow                      | memory_clusterd |         220.203 |         257.206 |   MB   |    50%     |      no       | better: 14.4% less

and without it (because I'm not sure whether or not the soft assert is enabled during these feature benchmarks; by the numbers, it seems to not be):

NAME                                | TYPE            |      THIS       |      OTHER      |  UNIT  | THRESHOLD  |  Regression?  | 'THIS' is
--------------------------------------------------------------------------------------------------------------------------------------------------------
InsertMultiRow                      | wallclock       |           1.962 |           0.887 |   s    |    10%     |    !!YES!!    | worse:   2.2 TIMES slower
InsertMultiRow                      | memory_mz       |         805.187 |         984.192 |   MB   |    20%     |      no       | better: 18.2% less
InsertMultiRow                      | memory_clusterd |         195.503 |         229.168 |   MB   |    50%     |      no       | better: 14.7% less

NAME                                | TYPE            |      THIS       |      OTHER      |  UNIT  | THRESHOLD  |  Regression?  | 'THIS' is
--------------------------------------------------------------------------------------------------------------------------------------------------------
InsertMultiRow                      | wallclock       |           1.966 |           0.880 |   s    |    10%     |    !!YES!!    | worse:   2.2 TIMES slower
InsertMultiRow                      | memory_mz       |         894.070 |        1035.690 |   MB   |    20%     |      no       | better: 13.7% less
InsertMultiRow                      | memory_clusterd |         225.163 |         224.113 |   MB   |    50%     |      no       | worse:   0.5% more

NAME                                | TYPE            |      THIS       |      OTHER      |  UNIT  | THRESHOLD  |  Regression?  | 'THIS' is
--------------------------------------------------------------------------------------------------------------------------------------------------------
InsertMultiRow                      | wallclock       |           1.966 |           0.894 |   s    |    10%     |    !!YES!!    | worse:   2.2 TIMES slower
InsertMultiRow                      | memory_mz       |         963.211 |         969.887 |   MB   |    20%     |      no       | better:  0.7% less
InsertMultiRow                      | memory_clusterd |         183.105 |         217.438 |   MB   |    50%     |      no       | better: 15.8% less

So there's definitely still a slowdown, but not quite as egregious as it was before.

@mgree mgree merged commit 6746cbf into MaterializeInc:main Dec 19, 2024
80 of 89 checks passed
@mgree mgree deleted the cache-hash-to-slash-overhead branch December 19, 2024 20:21
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