@@ -13,14 +13,14 @@ import (
1313 "syscall"
1414 "time"
1515
16- "github.com/bits-and-blooms/bitset "
16+ "github.com/RoaringBitmap/roaring/v2 "
1717 "github.com/edsrzf/mmap-go"
1818 "go.opentelemetry.io/otel"
1919 "go.opentelemetry.io/otel/attribute"
2020 "go.uber.org/zap"
2121 "golang.org/x/sys/unix"
2222
23- "github.com/e2b-dev/infra/packages/shared/pkg/atomicbitset "
23+ "github.com/e2b-dev/infra/packages/shared/pkg/syncroaring "
2424 "github.com/e2b-dev/infra/packages/shared/pkg/logger"
2525 "github.com/e2b-dev/infra/packages/shared/pkg/storage/header"
2626 "github.com/e2b-dev/infra/packages/shared/pkg/telemetry"
@@ -53,7 +53,7 @@ type Cache struct {
5353 blockSize int64
5454 mmap * mmap.MMap
5555 mu sync.RWMutex
56- dirty * atomicbitset .Bitset
56+ dirty * syncroaring .Bitset
5757 dirtyFile bool
5858 closed atomic.Bool
5959}
@@ -72,7 +72,7 @@ func NewCache(size, blockSize int64, filePath string, dirtyFile bool) (*Cache, e
7272 size : size ,
7373 blockSize : blockSize ,
7474 dirtyFile : dirtyFile ,
75- dirty : atomicbitset .New (),
75+ dirty : syncroaring .New (),
7676 }, nil
7777 }
7878
@@ -97,7 +97,7 @@ func NewCache(size, blockSize int64, filePath string, dirtyFile bool) (*Cache, e
9797 size : size ,
9898 blockSize : blockSize ,
9999 dirtyFile : dirtyFile ,
100- dirty : atomicbitset .New (),
100+ dirty : syncroaring .New (),
101101 }, nil
102102}
103103
@@ -117,7 +117,7 @@ func (c *Cache) ExportToDiff(ctx context.Context, out *os.File) (*header.DiffMet
117117 }
118118
119119 if c .mmap == nil {
120- return header .NewDiffMetadata (c .blockSize , bitset .New (0 )), nil
120+ return header .NewDiffMetadata (c .blockSize , roaring .New ()), nil
121121 }
122122
123123 f , err := os .Open (c .filePath )
@@ -136,7 +136,7 @@ func (c *Cache) ExportToDiff(ctx context.Context, out *os.File) (*header.DiffMet
136136 logger .L ().Warn (ctx , "error syncing file" , zap .Error (err ))
137137 }
138138
139- diffMetadata := header .NewDiffMetadata (c .blockSize , c .dirty .BitSet ())
139+ diffMetadata := header .NewDiffMetadata (c .blockSize , c .dirty .UnsafeBitmap ())
140140
141141 dst := int (out .Fd ())
142142 var writeOffset int64
@@ -194,7 +194,7 @@ func (c *Cache) ExportToDiff(ctx context.Context, out *os.File) (*header.DiffMet
194194 telemetry .SetAttributes (ctx ,
195195 attribute .Int64 ("copy_ms" , time .Since (copyStart ).Milliseconds ()),
196196 attribute .Int64 ("total_size_bytes" , c .size ),
197- attribute .Int64 ("dirty_size_bytes" , int64 (diffMetadata .Dirty .Count ())* c .blockSize ),
197+ attribute .Int64 ("dirty_size_bytes" , int64 (diffMetadata .Dirty .GetCardinality ())* c .blockSize ),
198198 attribute .Int64 ("total_ranges" , totalRanges ),
199199 )
200200
0 commit comments