Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Register
Sign in
Toggle navigation
Menu
Open sidebar
Tiger Ton
osmosis
Commits
517562dd
Commit
517562dd
authored
3 years ago
by
ValarDragon
Browse files
Options
Download
Email Patches
Plain Diff
Cache the unmarshalling, 5x improving init genesis time.
parent
6ebe3b48
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
x/lockup/keeper/store.go
+18
-0
x/lockup/keeper/store.go
with
18 additions
and
0 deletions
+18
-0
x/lockup/keeper/store.go
+
18
-
0
View file @
517562dd
package
keeper
import
(
"bytes"
"encoding/binary"
"encoding/json"
"fmt"
...
...
@@ -33,12 +34,28 @@ func lockStoreKey(ID uint64) []byte {
return
combineKeys
(
types
.
KeyPrefixPeriodLock
,
sdk
.
Uint64ToBigEndian
(
ID
))
}
type
cacheEntry
struct
{
key
[]
byte
value
[]
uint64
}
var
lastMarshalsCache
map
[
string
]
cacheEntry
func
init
()
{
lastMarshalsCache
=
make
(
map
[
string
]
cacheEntry
)
}
// getLockRefs get lock IDs specified on the prefix and timestamp key
func
(
k
Keeper
)
getLockRefs
(
ctx
sdk
.
Context
,
key
[]
byte
)
[]
uint64
{
store
:=
ctx
.
KVStore
(
k
.
storeKey
)
lockIDs
:=
[]
uint64
{}
if
store
.
Has
(
key
)
{
bz
:=
store
.
Get
(
key
)
if
val
,
ok
:=
lastMarshalsCache
[
string
(
key
)];
ok
{
if
bytes
.
Equal
(
bz
,
val
.
key
)
{
return
val
.
value
}
}
err
:=
json
.
Unmarshal
(
bz
,
&
lockIDs
)
if
err
!=
nil
{
panic
(
err
)
...
...
@@ -59,6 +76,7 @@ func (k Keeper) addLockRefByKey(ctx sdk.Context, key []byte, lockID uint64) erro
if
err
!=
nil
{
return
err
}
lastMarshalsCache
[
string
(
key
)]
=
cacheEntry
{
key
:
bz
,
value
:
lockIDs
}
store
.
Set
(
key
,
bz
)
return
nil
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets