Skip to content

Commit

Permalink
Caplin: indexing to use right buf size (#9998)
Browse files Browse the repository at this point in the history
- PutUvarint can produce 10 bytes
- re-using buffer - faster and less gc
  • Loading branch information
AskAlexSharov authored Apr 21, 2024
1 parent 86dd0e5 commit 54a1609
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 1 addition & 3 deletions turbo/snapshotsync/freezeblocks/block_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -2100,7 +2100,7 @@ func HeadersIdx(ctx context.Context, info snaptype.FileInfo, salt uint32, tmpDir
}

func BodiesIdx(ctx context.Context, info snaptype.FileInfo, salt uint32, tmpDir string, p *background.Progress, lvl log.Lvl, logger log.Logger) (err error) {
num := make([]byte, 8)
num := make([]byte, binary.MaxVarintLen64)

if err := Idx(ctx, info, salt, info.From, tmpDir, log.LvlDebug, p, func(idx *recsplit.RecSplit, i, offset uint64, _ []byte) error {
if p != nil {
Expand All @@ -2126,11 +2126,9 @@ func Idx(ctx context.Context, info snaptype.FileInfo, salt uint32, firstDataID u
}()

d, err := seg.NewDecompressor(info.Path)

if err != nil {
return fmt.Errorf("can't open %s for indexing: %w", info.Name(), err)
}

defer d.Close()

if p != nil {
Expand Down
6 changes: 3 additions & 3 deletions turbo/snapshotsync/freezeblocks/caplin_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ import (
var sidecarSSZSize = (&cltypes.BlobSidecar{}).EncodingSizeSSZ()

func BeaconSimpleIdx(ctx context.Context, sn snaptype.FileInfo, salt uint32, tmpDir string, p *background.Progress, lvl log.Lvl, logger log.Logger) (err error) {
num := make([]byte, binary.MaxVarintLen64)
if err := Idx(ctx, sn, salt, sn.From, tmpDir, log.LvlDebug, p, func(idx *recsplit.RecSplit, i, offset uint64, word []byte) error {
if i%20_000 == 0 {
logger.Log(lvl, fmt.Sprintf("Generating idx for %s", sn.Type.String()), "progress", i)
}
p.Processed.Add(1)
num := make([]byte, 8)
n := binary.PutUvarint(num, i)
if err := idx.AddKey(num[:n], offset); err != nil {
return err
Expand Down Expand Up @@ -495,7 +495,7 @@ func DumpBeaconBlocks(ctx context.Context, db kv.RoDB, fromSlot, toSlot uint64,
return nil
}

func DumpBlobsSidecar(ctx context.Context, blobStorage blob_storage.BlobStorage, db kv.RoDB, fromSlot, toSlot uint64, salt uint32, dirs datadir.Dirs, workers int, lvl log.Lvl, logger log.Logger) error {
func DumpBlobsSidecar(ctx context.Context, blobStorage blob_storage.BlobStorage, db kv.RoDB, fromSlot, toSlot uint64, salt uint32, dirs datadir.Dirs, compressWorkers int, lvl log.Lvl, logger log.Logger) error {
for i := fromSlot; i < toSlot; i = chooseSegmentEnd(i, toSlot, nil) {
blocksPerFile := snapcfg.MergeLimit("", i)

Expand All @@ -504,7 +504,7 @@ func DumpBlobsSidecar(ctx context.Context, blobStorage blob_storage.BlobStorage,
}
to := chooseSegmentEnd(i, toSlot, nil)
logger.Log(lvl, "Dumping blobs sidecars", "from", i, "to", to)
if err := dumpBlobSidecarsRange(ctx, db, blobStorage, i, to, salt, dirs, workers, lvl, logger); err != nil {
if err := dumpBlobSidecarsRange(ctx, db, blobStorage, i, to, salt, dirs, compressWorkers, lvl, logger); err != nil {
return err
}
}
Expand Down

0 comments on commit 54a1609

Please sign in to comment.