-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strict plutus-cbor #213
Strict plutus-cbor #213
Conversation
No performance improvement, but was a potential space leak?
Slight improvement in cpu time
No noticable performance improvement, but same potential space leak as in encodeMap
This should have subtractions be performed right away. Small improvement on benchmark
This did not achieve a noticable improvement, but made all functions consistent in their strictness behavior with internal functions
I just realized that this is breaking the normal plutus compilation of our validators using these functions 😓 |
@@ -86,7 +87,7 @@ import PlutusTx.Builtins (subtractInteger) | |||
newtype Encoding = Encoding (BuiltinByteString -> BuiltinByteString) | |||
|
|||
instance Semigroup Encoding where | |||
(Encoding a) <> (Encoding b) = Encoding (a . b) | |||
(Encoding f) <> (Encoding g) = Encoding (\(!x) -> f $ g x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't want that one... Being too strict is also not good as it prevents some compiler optimizations. Here, I'd heavily favor the composition over strictness.. I don't think it buys us much.
@@ -115,7 +116,7 @@ encodeBool = \case | |||
-- | |||
-- Note (2): This can only encode numbers up to @2^64 - 1@ and down to @-2^63@ | |||
encodeInteger :: Integer -> Encoding | |||
encodeInteger n | |||
encodeInteger !n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed as well.
@@ -124,14 +125,15 @@ encodeInteger n | |||
|
|||
-- | Encode a 'BuiltinByteString' as a CBOR type-02 major type. | |||
encodeByteString :: BuiltinByteString -> Encoding | |||
encodeByteString bytes = | |||
encodeByteString !bytes = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same 😅
@@ -161,7 +163,7 @@ encodeBreak = Encoding (consByteString 0xFF) | |||
-- <> encodeInteger 42 | |||
-- @ | |||
encodeListLen :: Integer -> Encoding | |||
encodeListLen = Encoding . encodeUnsigned 4 | |||
encodeListLen !n = Encoding (encodeUnsigned 4 n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also favor Lazyness and composition here.
@@ -188,7 +190,7 @@ encodeList :: (a -> Encoding) -> [a] -> Encoding | |||
encodeList encodeElem = | |||
step 0 mempty | |||
where | |||
step n bs = \case | |||
step !n !bs = \case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is definitely needed!
I guess we can close that one? |
Introducing more strictness to plutus-cbor
Could shave off about 30% on computation time on the expensive 100 asset case, but still not linear in input data! That means, that benchmarking in Haskell is still vastly different than evaluating & estimating execution costs in plutus.
Before:
![image](https://user-images.githubusercontent.com/2621189/153219511-da0ed9f0-738f-44ac-8d8c-39d09d126b6a.png)
After:
![image](https://user-images.githubusercontent.com/2621189/153219444-b72233d4-fa3b-426a-8f1d-85000058b309.png)