From abc59fa96802f1b79fc92ba3a4ae78b58b905535 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sat, 15 Feb 2020 21:28:12 +0100 Subject: [PATCH] contentenc: encryptBlocksParallel: explain why last part runs in new goroutine The result is counter-intuitive, so explain it here. --- internal/contentenc/content.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/contentenc/content.go b/internal/contentenc/content.go index 81864d4..697026a 100644 --- a/internal/contentenc/content.go +++ b/internal/contentenc/content.go @@ -219,7 +219,11 @@ func (be *ContentEnc) encryptBlocksParallel(plaintextBlocks [][]byte, ciphertext low := i * groupSize high := (i + 1) * groupSize if i == ncpu-1 { - // Last group, pick up any left-over blocks + // Last part picks up any left-over blocks + // + // The last part could run in the original goroutine, but + // doing that complicates the code, and, surprisingly, + // incurs a 1 % performance penalty. high = len(plaintextBlocks) } be.doEncryptBlocks(plaintextBlocks[low:high], ciphertextBlocks[low:high], firstBlockNo+uint64(low), fileID)