From c09eedf6fe71d0ac76bd6c581bc1ceed92efd493 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 3 Jul 2024 17:50:10 +0800 Subject: [PATCH] Problem: redundant copy in check validate (#1501) free key update doc cleanup --- CHANGELOG.md | 2 +- versiondb/tsrocksdb/iterator.go | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab87efea6a..609ee9e3bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * (versiondb) [#1491](https://github.com/crypto-org-chain/cronos/pull/1491) Free slice data in HasAtVersion. * [#1489](https://github.com/crypto-org-chain/cronos/pull/1489) Update cometbft to v0.37.7. +* (versiondb) [#1498](https://github.com/crypto-org-chain/cronos/pull/1498) Reduce scope of copying slice data in iterator. *Jun 18, 2024* @@ -33,7 +34,6 @@ * (e2ee)[#1415](https://github.com/crypto-org-chain/cronos/pull/1415) Add batch keys query for e2ee module. * (e2ee)[#1421](https://github.com/crypto-org-chain/cronos/pull/1421) Validate e2ee key when register. * [#1437](https://github.com/crypto-org-chain/cronos/pull/1437) Update cometbft and cosmos-sdk dependencies. -* (rpc) [#1467](https://github.com/crypto-org-chain/cronos/pull/1467) Avoid unnecessary tx decode in tx listener. ### Bug Fixes diff --git a/versiondb/tsrocksdb/iterator.go b/versiondb/tsrocksdb/iterator.go index c6089d330b..f4c4b3c777 100644 --- a/versiondb/tsrocksdb/iterator.go +++ b/versiondb/tsrocksdb/iterator.go @@ -23,8 +23,9 @@ func newRocksDBIterator(source *grocksdb.Iterator, prefix, start, end []byte, is } else { source.Seek(end) if source.Valid() { - eoakey := moveSliceToBytes(source.Key()) // end or after key - if bytes.Compare(end, eoakey) <= 0 { + eoakey := source.Key() // end or after key + defer eoakey.Free() + if bytes.Compare(end, eoakey.Data()) <= 0 { source.Prev() } } else { @@ -75,14 +76,15 @@ func (itr *rocksDBIterator) Valid() bool { // If key is end or past it, invalid. start := itr.start end := itr.end - key := moveSliceToBytes(itr.source.Key()) + key := itr.source.Key() + defer key.Free() if itr.isReverse { - if start != nil && bytes.Compare(key, start) < 0 { + if start != nil && bytes.Compare(key.Data(), start) < 0 { itr.isInvalid = true return false } } else { - if end != nil && bytes.Compare(end, key) <= 0 { + if end != nil && bytes.Compare(end, key.Data()) <= 0 { itr.isInvalid = true return false }