From e0b9d744cffacf6217ad9b48e3da8de7bb111e49 Mon Sep 17 00:00:00 2001 From: Andrew Martin Date: Sun, 22 Sep 2019 09:34:55 -0400 Subject: [PATCH] double buffer size, rather than increasing it by a constant factor, on every iteration in builder run function --- src/Data/ByteArray/Builder.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Data/ByteArray/Builder.hs b/src/Data/ByteArray/Builder.hs index 146926a..053018b 100644 --- a/src/Data/ByteArray/Builder.hs +++ b/src/Data/ByteArray/Builder.hs @@ -92,8 +92,9 @@ import qualified Data.Vector as V import qualified Data.ByteArray.Builder.Bounded as Bounded import qualified Data.ByteArray.Builder.Bounded.Unsafe as UnsafeBounded --- | Run a builder. An accurate size hint is important for good performance. --- The size hint should be slightly larger than the actual size. +-- | Run a builder. An accurate size hint is important for +-- good performance. The size hint should be slightly greater +-- than or equal to the actual size. run :: Int -- ^ Hint for upper bound on size -> Builder -- ^ Builder @@ -102,11 +103,11 @@ run hint b = runByteArrayST $ do let go !n = do arr <- PM.newByteArray n pasteST b (MutableBytes arr 0 n) >>= \case - Nothing -> go (n + 64) + Nothing -> go (n + n + 16) Just len -> do shrinkMutableByteArray arr len PM.unsafeFreezeByteArray arr - go (max hint 1) + go (max hint 16) -- | Variant of 'pasteArrayST' that runs in 'IO'. pasteArrayIO ::