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

store/cachekv: use typed types/kv.List instead of container/list.List #8811

Merged
merged 2 commits into from
Mar 8, 2021

Commits on Mar 7, 2021

  1. store/cachekv: use typed types/kv.List instead of container/list.List

    Reduces CPU burn by using a typed List to avoid the expensive type
    assertions from using an interface. This is the only option for now
    until Go makes generics generally available.
    
    The change brings time spent on the time assertion cummulatively to:
        580ms down from 6.88s
    
    Explanation:
    The type assertions were showing up heavily in profiles:
    * Before this commit
    ```shell
    Total: 42.18s
    ROUTINE ======================== github.com/cosmos/cosmos-sdk/store/cachekv.newMemIterator
    in /Users/emmanuelodeke/go/src/github.com/cosmos/cosmos-sdk/store/cachekv/memiterator.go
        14.01s     18.87s (flat, cum) 44.74% of Total
             .          .     17:	items      []*kv.Pair
             .          .     18:	ascending  bool
             .          .     19:}
             .          .     20:
             .          .     21:func newMemIterator(start, end []byte, items *list.List, ascending bool) *memIterator {
             .      620ms     22:	itemsInDomain := make([]*kv.Pair, 0, items.Len())
             .          .     23:
             .          .     24:	var entered bool
             .          .     25:
         510ms      870ms     26:	for e := items.Front(); e != nil; e = e.Next() {
         6.85s      6.88s     27:		item := e.Value.(*kv.Pair)
         5.71s      8.19s     28:		if !dbm.IsKeyInDomain(item.Key, start, end) {
         120ms      120ms     29:			if entered {
             .          .     30:				break
             .          .     31:			}
             .          .     32:
             .          .     33:			continue
             .          .     34:		}
             .          .     35:
         820ms      980ms     36:		itemsInDomain = append(itemsInDomain, item)
             .          .     37:		entered = true
             .          .     38:	}
             .          .     39:
             .      1.21s     40:	return &memIterator{
             .          .     41:		start:     start,
             .          .     42:		end:       end,
             .          .     43:		items:     itemsInDomain,
             .          .     44:		ascending: ascending,
             .          .     45:	}
    ```
    
    and given that the list only uses that type, it is only right to lift the
    code from container/list.List, and only modify Element.Value's type.
    
    For emphasis, the code is basically just a retrofit of
    container/list/list.go but with a typing, and we'll keep it as is
    until perhaps Go1.17 or Go1.18 or when everyone uses Go1.17+ after
    generics have landed.
    
    * After this commit
    ```shell
    Total: 45.25s
    ROUTINE ======================== github.com/cosmos/cosmos-sdk/store/cachekv.newMemIterator
    in /Users/emmanuelodeke/go/src/github.com/cosmos/cosmos-sdk/store/cachekv/memiterator.go
         4.84s      6.77s (flat, cum) 14.96% of Total
             .          .     16:	items      []*kv.Pair
             .          .     17:	ascending  bool
             .          .     18:}
             .          .     19:
             .          .     20:func newMemIterator(start, end []byte, items *kv.List, ascending bool) *memIterator {
             .      330ms     21:	itemsInDomain := make([]*kv.Pair, 0, items.Len())
             .          .     22:
             .          .     23:	var entered bool
             .          .     24:
          60ms      160ms     25:	for e := items.Front(); e != nil; e = e.Next() {
         580ms      580ms     26:		item := e.Value
         3.68s      4.78s     27:		if !dbm.IsKeyInDomain(item.Key, start, end) {
          80ms       80ms     28:			if entered {
             .          .     29:				break
             .          .     30:			}
             .          .     31:
             .          .     32:			continue
             .          .     33:		}
             .          .     34:
         440ms      580ms     35:		itemsInDomain = append(itemsInDomain, item)
             .          .     36:		entered = true
             .          .     37:	}
             .          .     38:
             .      260ms     39:	return &memIterator{
             .          .     40:		start:     start,
             .          .     41:		end:       end,
             .          .     42:		items:     itemsInDomain,
             .          .     43:		ascending: ascending,
             .          .     44:	}
    ```
    
    Fixes #8810
    odeke-em committed Mar 7, 2021
    Configuration menu
    Copy the full SHA
    e3ea4cd View commit details
    Browse the repository at this point in the history

Commits on Mar 8, 2021

  1. Configuration menu
    Copy the full SHA
    fd18e9f View commit details
    Browse the repository at this point in the history