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

Problem: redundant copy in check validate #1498

Merged
merged 5 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* [#1488](https://github.com/crypto-org-chain/cronos/pull/1488) Enable optimistic execution.
* [#1490](https://github.com/crypto-org-chain/cronos/pull/1490) Update cometbft to v0.38.8.
* [#1491](https://github.com/crypto-org-chain/cronos/pull/1491) Free slice data in HasAtVersion.
* [#1498](https://github.com/crypto-org-chain/cronos/pull/1498) Check validity with extractSliceBytes to avoid copying slice data.

### Bug Fixes

Expand Down
14 changes: 12 additions & 2 deletions versiondb/tsrocksdb/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
} else {
source.Seek(end)
if source.Valid() {
eoakey := moveSliceToBytes(source.Key()) // end or after key
eoakey := extractSliceBytes(source.Key()) // end or after key
if bytes.Compare(end, eoakey) <= 0 {
source.Prev()
}
Expand Down Expand Up @@ -75,7 +75,7 @@
// If key is end or past it, invalid.
start := itr.start
end := itr.end
key := moveSliceToBytes(itr.source.Key())
key := extractSliceBytes(itr.source.Key())
if itr.isReverse {
if start != nil && bytes.Compare(key, start) < 0 {
itr.isInvalid = true
Expand Down Expand Up @@ -143,3 +143,13 @@
copy(v, s.Data())
return v
}

// extractSliceBytes returns the underlying []byte from the given *Slice
// without copying the data. Use this function with caution as the *Slice
// should not be used after calling this function, as it is not marked as freed.
func extractSliceBytes(s *grocksdb.Slice) []byte {
if !s.Exists() {
return nil

Check warning on line 152 in versiondb/tsrocksdb/iterator.go

View check run for this annotation

Codecov / codecov/patch

versiondb/tsrocksdb/iterator.go#L152

Added line #L152 was not covered by tests
}
return s.Data()
}
yihuang marked this conversation as resolved.
Show resolved Hide resolved
Loading