perf: optimize transaction lookups, cache filtering, and fix resource leaks#332
Open
pannous wants to merge 2 commits into
Open
perf: optimize transaction lookups, cache filtering, and fix resource leaks#332pannous wants to merge 2 commits into
pannous wants to merge 2 commits into
Conversation
- TransactionImporter: add O(1) signature index (ByteArray HashSet) replacing O(n) linear stream scan in incomingTransactionQueueContains(), which is called on every incoming transaction signature from every peer - OnlineAccountsManager: pre-build HashSet of existing public keys before minting account loop, replacing O(n) stream scan per iteration; also optimize matching count calculation from O(n*m) to O(n+m) - HSQLDBCacheUtils: fix duplicate keyword filter bug (filter was applied twice), reduce two-pass metadata/status stripping to single-pass map operation, add try-with-resources for Statement/ResultSet in fillNamepMap, getResources, and getAccountBalances to prevent JDBC resource leaks
There was a problem hiding this comment.
Pull request overview
Performance optimizations targeting three hot paths: O(1) transaction signature lookups via ByteArray HashSet index, pre-built lookup sets for online account public keys, and single-pass metadata/status stripping. Also fixes a duplicate keyword filter bug and adds try-with-resources for JDBC resource cleanup.
Changes:
- Replace O(n) linear scans with O(1) HashSet lookups in
TransactionImporterandOnlineAccountsManagerusingByteArraywrapper - Fix duplicate keyword filter block and simplify metadata/status stripping to single-pass in
HSQLDBCacheUtils.filterList() - Add try-with-resources for
Statement/ResultSetin three database methods to prevent JDBC resource leaks
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
HSQLDBCacheUtils.java |
Remove duplicate keyword filter, single-pass metadata/status stripping, try-with-resources for JDBC resources |
TransactionImporter.java |
Add incomingSignatureIndex HashSet for O(1) signature contains-check |
OnlineAccountsManager.java |
Pre-build HashSet of public keys to avoid O(n*m) nested stream scans |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+730
to
+792
| @@ -841,6 +789,8 @@ private static List<ArbitraryResourceData> getResources( Repository repository) | |||
| resources.add( arbitraryResourceData ); | |||
| } while (resultSet.next()); | |||
|
|
|||
| } // try-with-resources closes Statement and ResultSet | |||
Align the code inside the try-with-resources block in getResources() with the indentation style used in fillNamepMap() and getAccountBalances(). Also consolidated the two early-return null/empty checks into one and removed the trailing comment on the closing brace.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Performance and scalability improvements targeting three hot paths identified through code analysis:
TransactionImporter: O(1) signature lookup —
incomingTransactionQueueContains()previously did a full O(n) linear stream scan withArrays.equalson every call. Added aByteArrayHashSet index (incomingSignatureIndex) for constant-time contains checks. This method is called for every incoming transaction signature from every peer, so the improvement scales with both queue size and peer count.OnlineAccountsManager: eliminate O(n) per-iteration lookups — The minting account loop was calling
onlineAccounts.stream().anyMatch(Arrays.equals(...))per iteration, creating O(nm) complexity. Pre-build aHashSet<ByteArray>of existing public keys before the loop for O(1) lookups. Also optimized the matching count calculation from O(nm) nested streams to O(n+m).HSQLDBCacheUtils: bug fix + optimization + resource cleanup
stream.map()operationtry-with-resourcesforStatementandResultSetinfillNamepMap(),getResources(), andgetAccountBalances()to prevent JDBC resource leaks under loadTest plan
HSQLDBCacheUtilsTestspass (including metadata/status inclusion/exclusion tests)ByteArrayTestspassmvn compileAddresses #122