Skip to content

Commit 12c0101

Browse files
committed
contentenc: add PReqPool and use it in DecryptBlocks
This gets us a massive speed boost in streaming reads.
1 parent e4b5005 commit 12c0101

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

internal/contentenc/content.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ type ContentEnc struct {
6060
CReqPool bPool
6161
// Plaintext block pool. Always returns plainBS-sized byte slices.
6262
pBlockPool bPool
63+
// Plaintext request data pool. Slice have size fuse.MAX_KERNEL_WRITE.
64+
PReqPool bPool
6365
}
6466

6567
// New returns an initialized ContentEnc instance.
@@ -80,6 +82,7 @@ func New(cc *cryptocore.CryptoCore, plainBS uint64, forceDecode bool) *ContentEn
8082
cBlockPool: newBPool(int(cipherBS)),
8183
CReqPool: newBPool(cReqSize),
8284
pBlockPool: newBPool(int(plainBS)),
85+
PReqPool: newBPool(fuse.MAX_KERNEL_WRITE),
8386
}
8487
return c
8588
}
@@ -98,7 +101,7 @@ func (be *ContentEnc) CipherBS() uint64 {
98101
func (be *ContentEnc) DecryptBlocks(ciphertext []byte, firstBlockNo uint64, fileID []byte) ([]byte, error) {
99102
cBuf := bytes.NewBuffer(ciphertext)
100103
var err error
101-
var pBuf bytes.Buffer
104+
pBuf := bytes.NewBuffer(be.PReqPool.Get()[:0])
102105
for cBuf.Len() > 0 {
103106
cBlock := cBuf.Next(int(be.cipherBS))
104107
var pBlock []byte

internal/fusefrontend/file.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,10 @@ func (f *file) doRead(dst []byte, off uint64, length uint64) ([]byte, fuse.Statu
214214
}
215215
// else: out stays empty, file was smaller than the requested offset
216216

217-
return append(dst, out...), fuse.OK
217+
out = append(dst, out...)
218+
f.fs.contentEnc.PReqPool.Put(plaintext)
219+
220+
return out, fuse.OK
218221
}
219222

220223
// Read - FUSE call

0 commit comments

Comments
 (0)