File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
plutus-core/src/Data/Vector Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change
1
+ ### Changed
2
+
3
+ - The Flat serialisation format for UPLC built-in arrays was changed to use the encoder for lists instead of the encoder for the lazy ` Vector ` type.
4
+
Original file line number Diff line number Diff line change @@ -10,7 +10,15 @@ import Flat.Instances.Vector ()
10
10
instance (Hashable a ) => Hashable (Strict. Vector a ) where
11
11
hashWithSalt = Strict. foldl' hashWithSalt
12
12
13
+ {- The `flat` library does not provide a `Flat` instance for
14
+ `Vector.Strict.Vector`. We could encode and decode strict vectors by converting
15
+ them to and from lazy vectors (for which there is a `Flat` instance), but
16
+ experiments show that deserialisation is actually faster by about 5-10% if we
17
+ encode vectors as lists. This incurs a slight size penalty (lists require one
18
+ bit of overhead per entry whereas vectors can be encoded with an overhead of one
19
+ byte per 255 elements), but this is offset by the decoding speedup. Encoding
20
+ vectors as lists also simplifies maintenance and specification. -}
13
21
instance (Flat a ) => Flat (Strict. Vector a ) where
14
- size = size . Strict. toLazy -- Strict to Lazy is O(1)
15
- encode = encode . Strict. toLazy
16
- decode = Strict. fromLazy <$> decode -- Strict from Lazy is O(1)
22
+ size = size . Strict. toList
23
+ encode = encode . Strict. toList
24
+ decode = Strict. fromList <$> decode
You can’t perform that action at this time.
0 commit comments