fix(api): Optimize memory allocation for the filter interface of JSON-RPC#6495
Merged
kuny0707 merged 1 commit intotronprotocol:release_v4.8.1from Dec 24, 2025
Merged
Conversation
bladehan1
reviewed
Dec 19, 2025
0xbigapple
reviewed
Dec 19, 2025
0xbigapple
reviewed
Dec 19, 2025
framework/src/main/java/org/tron/core/services/jsonrpc/TronJsonRpc.java
Outdated
Show resolved
Hide resolved
bladehan1
approved these changes
Dec 19, 2025
framework/src/main/java/org/tron/core/services/jsonrpc/TronJsonRpcImpl.java
Outdated
Show resolved
Hide resolved
framework/src/main/java/org/tron/core/services/jsonrpc/TronJsonRpcImpl.java
Outdated
Show resolved
Hide resolved
chainbase/src/main/java/org/tron/core/db2/core/SnapshotManager.java
Outdated
Show resolved
Hide resolved
framework/src/main/java/org/tron/common/logsfilter/EventPluginLoader.java
Outdated
Show resolved
Hide resolved
Federico2014
approved these changes
Dec 19, 2025
0xbigapple
approved these changes
Dec 19, 2025
framework/src/main/java/org/tron/core/services/jsonrpc/TronJsonRpcImpl.java
Show resolved
Hide resolved
halibobo1205
approved these changes
Dec 19, 2025
lvs0075
approved these changes
Dec 22, 2025
0xbigapple
reviewed
Dec 23, 2025
| public int jsonRpcMaxSubTopics = 1000; | ||
| @Getter | ||
| @Setter | ||
| public int jsonRpcMaxFilterNum = 50000; |
Contributor
There was a problem hiding this comment.
Has this default value been tested, or is there any other reference for it?
Author
There was a problem hiding this comment.
Yes. It has been tested for mainnet. But nile should set it as 30000 or smaller.
bladehan1
approved these changes
Dec 23, 2025
framework/src/main/java/org/tron/core/services/jsonrpc/TronJsonRpc.java
Outdated
Show resolved
Hide resolved
framework/src/main/java/org/tron/core/services/jsonrpc/TronJsonRpcImpl.java
Outdated
Show resolved
Hide resolved
framework/src/main/java/org/tron/core/services/jsonrpc/TronJsonRpcImpl.java
Outdated
Show resolved
Hide resolved
| continue; | ||
| } | ||
| entry.getValue().getResult().add(ByteArray.toJsonHex(blockFilterCapsule.getBlockHash())); | ||
| String finalBlockHash = blockHash; |
Contributor
There was a problem hiding this comment.
what about moving cache lookup outside the loop to avoid redundant queries.
Since originalBlockHash is constant, querying the cache N times in the
loop is unnecessary. Moving it outside:
- Reduces O(N) cache accesses to O(1)
- Improves performance with identical functionality
- Better error handling with fallback strategy
// Approach A: Optimal - Query the cache once outside the loop (Recommended)
final String originalBlockHash = ByteArray.toJsonHex(blockFilterCapsule.getBlockHash());
// Query the cache only once
String cachedBlockHash;
try {
cachedBlockHash = blockHashCache.get(originalBlockHash, () -> originalBlockHash);
} catch (ExecutionException e) {
logger.error("Getting/loading blockHash from cache failed", e);
cachedBlockHash = originalBlockHash; // Fallback: use the original value
}
// Use the cached result directly inside the loop
while (it.hasNext()) {
Entry<String, BlockFilterAndResult> entry = it.next();
if (entry.getValue().isExpire()) {
it.remove();
continue;
}
entry.getValue().getResult().add(cachedBlockHash);
}
Author
There was a problem hiding this comment.
It might put unnecessary blockHash into blockHashCache if filter map is empty. But it's a good suggestion
…newFilter, eth_newBlockFilter
kuny0707
approved these changes
Dec 24, 2025
6 tasks
0xbigapple
added a commit
to 0xbigapple/java-tron
that referenced
this pull request
Jan 20, 2026
…, eth_newFilter, eth_newBlockFilter (tronprotocol#6495)
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.
What does this PR do?
eth_newFilter,eth_newBlockFilternode.jsonrpc.maxBlockFilterNumWhy are these changes required?
This PR has been tested by:
Follow up
Extra details