-
Notifications
You must be signed in to change notification settings - Fork 1
Attempting some stack safety strategies #2
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
base: nub-ord-bench
Are you sure you want to change the base?
Conversation
@@ -860,7 +880,10 @@ foldM f b (a : as) = f b a >>= \b' -> foldM f b' as | |||
-- | | |||
-- | Running time: `O(n)` | |||
mapReverse :: forall a b. (a -> b) -> List a -> List b | |||
mapReverse f = go Nil | |||
mapReverse f l = reverse $ map f l |
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.
Using this slower, but definitely stack safe alternative (not saying the other version is stack unsafe, but just trying to eliminate unknowns).
@@ -876,7 +899,10 @@ mapReverse f = go Nil | |||
-- | | |||
-- | Running time: `O(n)` | |||
addIndexReverse :: forall a. List a -> List (Tuple Int a) | |||
addIndexReverse = go 0 Nil | |||
addIndexReverse = reverse <<< mapWithIndex Tuple |
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 should be stack safe too, right?
b7b3690
to
8bae586
Compare
benchLists "nubBySafe" $ nubBySafe compare -- safe | ||
benchLists "addIndexReverse" addIndexReverse -- safe | ||
benchLists "mapReverse" $ mapReverse $ add 1 -- safe | ||
benchLists "sortBy" $ sortBy compare -- NOT SAFE!!!! |
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.
The problem
nubBy
's stack safety issue appears to be caused bynubByAdjacentReverse
, but that function is stack safe on it's own.