Skip to content

perf: use $hashCode in equals() #467

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 1 commit into from
Apr 17, 2025
Merged

Conversation

anthony-swirldslabs
Copy link
Contributor

Description:
Optimize generated models equals() method by checking the precomputed $hashCode before comparing all the fields individually.

Related issue(s):

Fixes #233

Notes for reviewer:
All test should pass.

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

Signed-off-by: Anthony Petrov <[email protected]>
Copy link

JUnit Test Report

   68 files  ±0     68 suites  ±0   3m 14s ⏱️ +23s
1 273 tests ±0  1 270 ✅ ±0   3 💤 ±0  0 ❌ ±0 
7 128 runs  ±0  7 109 ✅ ±0  19 💤 ±0  0 ❌ ±0 

Results for commit 38a70c9. ± Comparison against base commit 4c3935e.

This pull request removes 8 and adds 7 tests. Note that renamed tests count towards both.
, 1
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [1] FLOAT, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f170033aa68@3bc6c10f, [0.1, 0.5, 100.0], 12, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f170033ac78@3dcbbbc
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [1] STRING, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f17003479f8@63f2d024, [string 1, testing here, testing there], com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f1700347c08@7b2dd35d
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [2] BYTES, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f170034c000@798b36fd, [010203, ff7f0f, 42da07370bff], com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f170034c210@18ff1520
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [2] DOUBLE, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f170033ae88@29a1ec65, [0.1, 0.5, 100.0, 1.7653472635472653E240], 32, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f170033b098@625db0e0
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [3] BOOL, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f170033b2a8@1805ca5c, [true, false, false, true, true, true], 6, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f170033b4b8@3e61cffd
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [4] ENUM, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f170033b6c8@aa633e6, [Mock for EnumWithProtoMetadata, hashCode: 88764150, Mock for EnumWithProtoMetadata, hashCode: 300041864, Mock for EnumWithProtoMetadata, hashCode: 1674824156], 3, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f170033b8d8@3991fe6d
com.hedera.pbj.runtime.Utf8ToolsTest ‑ [4] 
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [1] FLOAT, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f85cc33aa68@3bc6c10f, [0.1, 0.5, 100.0], 12, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f85cc33ac78@3dcbbbc
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [1] STRING, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f85cc3479f8@63f2d024, [string 1, testing here, testing there], com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f85cc347c08@7b2dd35d
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [2] BYTES, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f85cc34c000@798b36fd, [010203, ff7f0f, 42da07370bff], com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f85cc34c210@18ff1520
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [2] DOUBLE, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f85cc33ae88@29a1ec65, [0.1, 0.5, 100.0, 1.7653472635472653E240], 32, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f85cc33b098@625db0e0
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [3] BOOL, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f85cc33b2a8@1805ca5c, [true, false, false, true, true, true], 6, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f85cc33b4b8@3e61cffd
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [4] ENUM, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f85cc33b6c8@aa633e6, [Mock for EnumWithProtoMetadata, hashCode: 88764150, Mock for EnumWithProtoMetadata, hashCode: 300041864, Mock for EnumWithProtoMetadata, hashCode: 1674824156], 3, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00007f85cc33b8d8@3991fe6d
com.hedera.pbj.runtime.Utf8ToolsTest ‑ [4] 
, 1

Copy link

Integration Test Report

    393 files  ±0      393 suites  ±0   13m 27s ⏱️ - 1m 12s
114 769 tests ±0  114 769 ✅ ±0  0 💤 ±0  0 ❌ ±0 
114 997 runs  ±0  114 997 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 38a70c9. ± Comparison against base commit 4c3935e.

This pull request removes 3 and adds 3 tests. Note that renamed tests count towards both.
com.hedera.pbj.integration.test.ParserNeverWrapsTest ‑ [1] com.hedera.pbj.integration.test.ParserNeverWrapsTest$$Lambda/0x00007f293860b230@2eba0e75
com.hedera.pbj.integration.test.ParserNeverWrapsTest ‑ [2] com.hedera.pbj.integration.test.ParserNeverWrapsTest$$Lambda/0x00007f293860b460@43ef6c15
com.hedera.pbj.integration.test.ParserNeverWrapsTest ‑ [3] com.hedera.pbj.integration.test.ParserNeverWrapsTest$$Lambda/0x00007f293860b690@171957b8
com.hedera.pbj.integration.test.ParserNeverWrapsTest ‑ [1] com.hedera.pbj.integration.test.ParserNeverWrapsTest$$Lambda/0x00007f90f0602918@64a42ea7
com.hedera.pbj.integration.test.ParserNeverWrapsTest ‑ [2] com.hedera.pbj.integration.test.ParserNeverWrapsTest$$Lambda/0x00007f90f0602b48@b60b041
com.hedera.pbj.integration.test.ParserNeverWrapsTest ‑ [3] com.hedera.pbj.integration.test.ParserNeverWrapsTest$$Lambda/0x00007f90f0602d78@8c7291

@anthony-swirldslabs anthony-swirldslabs merged commit 5157cba into main Apr 17, 2025
10 checks passed
@anthony-swirldslabs anthony-swirldslabs deleted the 233-equalsHashCode branch April 17, 2025 17:06
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.

Caching of Hashcode in generated objects
3 participants