Skip to content
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

[Evaluation] [Performance] Use 'unsafeShiftL' instead of '*' #6737

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Changed

- In #6737 made the the CEK creation operation marginally faster by resorting to bit manipulation
12 changes: 7 additions & 5 deletions plutus-core/index-envs/src/Data/RandomAccessList/SkewBinary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Data.RandomAccessList.SkewBinary
, uncons
) where

import Data.Bits (unsafeShiftR)
import Data.Bits (setBit, unsafeShiftL, unsafeShiftR)
import Data.Word
import GHC.Exts

Expand Down Expand Up @@ -51,8 +51,8 @@ null Nil = True
null _ = False
{-# INLINE null #-}

{-# complete Cons, Nil #-}
{-# complete BHead, Nil #-}
{-# COMPLETE Cons, Nil #-}
{-# COMPLETE BHead, Nil #-}

-- /O(1)/
pattern Cons :: a -> RAList a -> RAList a
Expand All @@ -62,8 +62,10 @@ pattern Cons x xs <- (uncons -> Just (x, xs)) where
-- O(1) worst-case
cons :: a -> RAList a -> RAList a
cons x = \case
(BHead w1 t1 (BHead w2 t2 ts')) | w1 == w2 -> BHead (2*w1+1) (Node x t1 t2) ts'
ts -> BHead 1 (Leaf x) ts
(BHead w1 t1 (BHead w2 t2 ts')) | w1 == w2 ->
-- 'unsafeShiftL w1 1 `setBit`0' is supposed to be a faster version of '(2*w1)+1'
BHead (unsafeShiftL w1 1 `setBit` 0) (Node x t1 t2) ts'
ts -> BHead 1 (Leaf x) ts
{-# INLINE cons #-}

-- /O(1)/
Expand Down
Loading