Skip to content

Commit

Permalink
Warmup sig-exists index
Browse files Browse the repository at this point in the history
  • Loading branch information
gagliardetto committed Sep 5, 2023
1 parent 4056a2a commit 577fa33
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bufio"
"context"
"crypto/rand"
"encoding/binary"
"errors"
"fmt"
Expand Down Expand Up @@ -231,6 +232,13 @@ func NewEpochFromConfig(config *Config, c *cli.Context) (*Epoch, error) {
}
ep.onClose = append(ep.onClose, sigExists.Close)

{
// warm up the cache
for i := 0; i < 100_000; i++ {
sigExists.Has(newRandomSignature())
}
}

ep.sigExists = sigExists
}

Expand All @@ -250,6 +258,12 @@ func NewEpochFromConfig(config *Config, c *cli.Context) (*Epoch, error) {
return ep, nil
}

func newRandomSignature() [64]byte {
var sig [64]byte
rand.Read(sig[:])
return sig
}

func (r *Epoch) getNodeFromCache(c cid.Cid) (v []byte, err error, has bool) {
if v, ok := r.cidToNodeCache.Get(c.String()); ok {
return v.([]byte), nil, true
Expand Down

0 comments on commit 577fa33

Please sign in to comment.