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

core: reuse buffers in persist() #772

Merged
merged 1 commit into from
Mar 25, 2020
Merged

core: reuse buffers in persist() #772

merged 1 commit into from
Mar 25, 2020

Conversation

fyrchik
Copy link
Contributor

@fyrchik fyrchik commented Mar 17, 2020

When flushing many key-value pairs, cost of a buffer grow (reallocation) can become significant.
This PR reduces it by reusing the same buffer for (*cacheddao).Persist().

@codecov
Copy link

codecov bot commented Mar 17, 2020

Codecov Report

Merging #772 into master will increase coverage by 0.01%.
The diff coverage is 94.44%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #772      +/-   ##
==========================================
+ Coverage   66.94%   66.96%   +0.01%     
==========================================
  Files         141      141              
  Lines       13034    13045      +11     
==========================================
+ Hits         8726     8735       +9     
- Misses       3898     3900       +2     
  Partials      410      410
Impacted Files Coverage Δ
pkg/core/cacheddao.go 83.9% <100%> (+0.77%) ⬆️
pkg/core/dao.go 69.87% <90.9%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 79b930f...c992d6c. Read the comment docs.

pkg/core/blockchain.go Outdated Show resolved Hide resolved
pkg/core/cacheddao.go Outdated Show resolved Hide resolved
pkg/core/dao.go Outdated Show resolved Hide resolved
@roman-khimov
Copy link
Member

I think I'm OK with fd6d3c1 if you're to change the API (dao and cachedDao are supposed to be interchangeable), but I don't think 0eb4b4f makes much sense, it can be dangerous, it complicates code, but the gain is probably not that huge (1 new buffer per 10-100 serializations is not a lot of overhead).

When serializing multiple accounts, cost of a buffer grow
can become significant. This commit tries to amortize it by
reusing the same buffer in a single `Persist()` call.
@roman-khimov roman-khimov added this to the v0.74.1 milestone Mar 25, 2020
@roman-khimov roman-khimov merged commit db2c4c7 into master Mar 25, 2020
@roman-khimov roman-khimov deleted the feature/reuse branch March 25, 2020 12:10
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.

None yet

2 participants