summaryrefslogtreecommitdiff
path: root/internal/cryptocore/nonce.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-06-09 21:52:26 +0200
committerJakob Unterwurzacher2017-06-09 22:05:14 +0200
commit80516ed3351477793eec882508969b6b29b69b0a (patch)
treec461bd49e79fd6d8bf7f5dc8f28058faf2ba3078 /internal/cryptocore/nonce.go
parentda1bd742461e397abefc814bb0c0a21a6d8ec3d6 (diff)
cryptocore: prefetch nonces in 512-byte blocks
On my machine, reading 512-byte blocks from /dev/urandom (same via getentropy syscall) is a lot faster in terms of throughput: Blocksize Throughput 16 28.18 MB/s 512 83.75 MB/s For a single-threaded streaming write, this drops the CPU usage of nonceGenerator.Get to almost 1/3: flat flat% sum% cum cum% Before 0 0% 95.08% 0.35s 2.92% github.com/rfjakob/gocryptfs/internal/cryptocore.(*nonceGenerator).Get After 0.01s 0.092% 92.34% 0.13s 1.20% github.com/rfjakob/gocryptfs/internal/cryptocore.(*nonceGenerator).Get This change makes the nonce reading single-threaded, which may hurt massively-parallel writes.
Diffstat (limited to 'internal/cryptocore/nonce.go')
-rw-r--r--internal/cryptocore/nonce.go3
1 files changed, 1 insertions, 2 deletions
diff --git a/internal/cryptocore/nonce.go b/internal/cryptocore/nonce.go
index 412cdbb..9df094c 100644
--- a/internal/cryptocore/nonce.go
+++ b/internal/cryptocore/nonce.go
@@ -28,6 +28,5 @@ type nonceGenerator struct {
// Get a random "nonceLen"-byte nonce
func (n *nonceGenerator) Get() []byte {
- nonce := RandBytes(n.nonceLen)
- return nonce
+ return randPrefetcher.read(n.nonceLen)
}