Skip to content
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

fix(store): caching account and validator in store #513

Merged
merged 6 commits into from
Jun 16, 2023

Conversation

b00f
Copy link
Collaborator

@b00f b00f commented Jun 16, 2023

Description

The primary objective of this PR is to enhance the performance of the software and it also aims to reduce the syncing time. Executing each transaction requires fetching the corresponding account or validator information from LevelDB. Since database read/write operations are costly, they can significantly impact performance.

To mitigate this, we've implemented caching for accounts and validators based on their addresses. This approach allows us to write data into the DB, while reading account or validator information is performed from the cached data.

Since we are utilizing a map for caching, the complexity of fetching data is O(1), which ensures optimal performance. However, if the number of accounts becomes large, for example more than 1 million, we may need to use an LRU cache.

Another modification introduced in this PR is the implementation of the clone function for validators and accounts. Within both the sandbox and store packages, we assign objects by pointer and return a cloned object.

@b00f b00f changed the title Store cache fix: caching account and validator in store Jun 16, 2023
@Ja7ad
Copy link
Contributor

Ja7ad commented Jun 16, 2023

@b00f All things is okay for merging.

@codecov
Copy link

codecov bot commented Jun 16, 2023

Codecov Report

Merging #513 (2bf897e) into main (f550c79) will increase coverage by 0.09%.
The diff coverage is 95.61%.

❗ Current head 2bf897e differs from pull request most recent head 29d705f. Consider uploading reports for the commit 29d705f to get more accurate results

@@            Coverage Diff             @@
##             main     #513      +/-   ##
==========================================
+ Coverage   83.05%   83.15%   +0.09%     
==========================================
  Files         154      154              
  Lines        7313     7306       -7     
==========================================
+ Hits         6074     6075       +1     
+ Misses        955      951       -4     
+ Partials      284      280       -4     

store/account_test.go Outdated Show resolved Hide resolved
types/account/account.go Outdated Show resolved Hide resolved
types/account/account.go Outdated Show resolved Hide resolved
types/account/account.go Outdated Show resolved Hide resolved
@themantre
Copy link
Contributor

Remove TestReturnNilForNonExistingItems test

store/account_test.go Outdated Show resolved Hide resolved
sandbox/sandbox_test.go Outdated Show resolved Hide resolved
@themantre themantre enabled auto-merge (squash) June 16, 2023 15:08
@themantre themantre merged commit 5e2f135 into pactus-project:main Jun 16, 2023
@b00f b00f deleted the store-cache branch June 16, 2023 15:33
@b00f b00f changed the title fix: caching account and validator in store fix(store): caching account and validator in store Jun 17, 2023
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.

3 participants