Skip to content

Improve Varbinary Hex Functions#14889

Merged
martint merged 4 commits intotrinodb:masterfrom
pettyjamesm:improve-varbinary-functions
Nov 8, 2022
Merged

Improve Varbinary Hex Functions#14889
martint merged 4 commits intotrinodb:masterfrom
pettyjamesm:improve-varbinary-functions

Conversation

@pettyjamesm
Copy link
Copy Markdown
Member

Description

This PR contains three minor improvements, in separate commits:

  • Improves performance of VarbinaryFunctions.{toHex,fromHexVarchar} implementations by avoiding intermediate String materializations and operating over the primitive byte arrays where possible.
  • Improves VarbinaryFunctions.crc32 to use the primitive byte array when possible instead of creating a new ByteBuffer to compute the crc32 value
  • Improves SqlVarbinary#toString by precomputing the exact output size required for the StringBuilder and using java.util.HexFormat instead of calling String.format as part of the per-byte inner loop.

Non-technical explanation

No non-technical explanation is necessary, this are not user visible changes.

Release notes

(x) This is not user-visible or 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 Nov 3, 2022
@pettyjamesm pettyjamesm force-pushed the improve-varbinary-functions branch 2 times, most recently from 3ccf8f6 to 36994ba Compare November 4, 2022 14:14
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use junit

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Currently trino-spi doesn't have junit on the classpath for testing dependencies and all the other tests are using org.testng.annotations.Test. Are we trying to switch the preferred annotations for new PR's over to junit instead?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We’re slowly trying to migrate to JUnit (#9378) so I think we should try to take the opportunity to use it when adding new tests. Otherwise, it’s more work someone has to do later.

Copy link
Copy Markdown
Member Author

@pettyjamesm pettyjamesm Nov 7, 2022

Choose a reason for hiding this comment

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

Got it- good to know. I tried switching just this one test to use jUnit, but it seemed like adding junit to trino-spi/pom.xml prevented all of the existing testng tests from running. A quick google search seemed to expose ways to run jUnit tests within TestNG, but I couldn't find anything about doing it the other way around- so it seems like using jUnit here would require migrating all of the trino-spi tests all at once, unless you know of a way to avoid it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nevermind, I see that trino-main/pom.xml has a configuration for allowing both to co-exist. I'll push a new commit in this PR to add jUnit support to trino-spi and migrate this new test to use those annotations instead.

@pettyjamesm pettyjamesm force-pushed the improve-varbinary-functions branch from 36994ba to 36267eb Compare November 7, 2022 16:58
Improves to_hex() and from_hex() functions performance by removing
extra String -> byte[] round-trips and operating over the underlying
byte arrays directly where possible.
Improves performance of convering SqlVarbinary values to Strings
by precomputing the exact string output size and avoiding an inner
loop call to String.format per byte.

Also switches SqlVarbinary#compareTo implementation to use the
Arrays.compare directly.
@pettyjamesm pettyjamesm force-pushed the improve-varbinary-functions branch from 36267eb to d2af93c Compare November 7, 2022 21:52
@martint martint merged commit a940ca0 into trinodb:master Nov 8, 2022
@pettyjamesm pettyjamesm deleted the improve-varbinary-functions branch November 8, 2022 21:38
@github-actions github-actions bot added this to the 403 milestone Nov 8, 2022
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.

2 participants