# Try to resolve slow iterator seek with preifx in some condition

**URL:** <https://discuss.dgraph.io/t/try-to-resolve-slow-iterator-seek-with-preifx-in-some-condition/14894>\
**Category:** Badger\
**Created:** [July 9, 2021, 12:48pm UTC](https://discuss.dgraph.io/t/try-to-resolve-slow-iterator-seek-with-preifx-in-some-condition/14894 "2021-07-09T12:48:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zzyalbert](https://avatars.discourse-cdn.com/v4/letter/z/d2c977/32.png) [@zzyalbert](https://discuss.dgraph.io/u/zzyalbert)\
**Post date:** [July 9, 2021, 12:48pm UTC](https://discuss.dgraph.io/t/try-to-resolve-slow-iterator-seek-with-preifx-in-some-condition/14894/1 "2021-07-09T12:48:26Z")

</div>

When I was trying to change the db engine to badgerdb in some of my projects, I found the iterator Seek with prefix was pretty slow in the following situation:

- lots of keys we were seeking with prefix didn’t exist
- lots of keys have lots of versions

Then I use `pprof` to found out the iterator was still running `parseItem` even if the current key was not match the prefix.  
[![image](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/8/8b80c845a99e00672282a1b9187fcd0169a0466d.png)](https://user-images.githubusercontent.com/8242525/124263418-cd735680-db65-11eb-9f6c-ba9856432430.png)

So I fix this by skipping the `parseItem` process when the current key is not match the prefix.

pr : [Improve Iterator Performance of Seeking with Prefix by zzyalbert · Pull Request #1719 · dgraph-io/badger · GitHub](https://github.com/dgraph-io/badger/pull/1719)

### What version of Go are you using (`go version`)?

```
go1.16.4
```

### What operating system are you using?

ubuntu

### What version of Badger are you using?

3.2103

### Does this issue reproduce with the latest master?

yes

### Steps to Reproduce the issue

when keys in badger has lots of versions, then iterator.Seek a prefix that didn’t exist.  
It was quite slow in compare with leveldb, even in minuts total when seeking 30000 non-existent prefix

### What Badger options were set?

default

### What did you do?

### What did you expect to see?

### What did you see instead?
