Here github.com/dgraph-io/badger/v3.(*Iterator).fill.func1 N=2033535
Creating huge number of Goroutine internally.
The significant time spent in Scheduler Wait.
How do we improve the prefix iteration performance? Is there any better approach for our use case?
Thanks
If you want to iterate over a prefix really fast and collect the results, you should consider using the Stream framework within Badger. It uses many goroutines to make iteration as fast as disk would allow.
https://pkg.go.dev/github.com/outcaste-io/badger/v3#Stream
Also, in general, using a Go channel to collect what could be millions of results would be really slow. Channels are best used by batching up the results and decreasing how many times you interact with them.
Stream Framework takes care of all of that by giving you a serially executed Stream.Send function. You can even keep the encoded data as it is, and decode it within the Send, or copy it over from Send.