Skip to content

Conversation

@ndmitchell
Copy link
Contributor

As part of my efforts to investigate space leaks, I ended up at the fold_lookahead function, which I rewrote as below. I offer this as an entirely separate patch because there are good reasons you might want to not merge it. Advantages:

  • Reduces stack usage from > 1Mb to < 1Kb.
  • Algorithm more directly states what it does.
  • Better time complexity - previously it was a combination of insertion sort on the Int and a weird order-changing nub construction on the Lr0Item.
  • Passes all the tests.

Disadvantages:

  • Has no meaningful time difference - my tests are with 0.03s.
  • Produces different output since the list is in a different order. I believe the results are equivalent, but you will need to say for sure.

@simonmar simonmar merged commit bc3e126 into haskell:master May 17, 2016
@simonmar
Copy link
Member

The patch looks sensible to me. This codebase is very very very old you know :)

@ndmitchell
Copy link
Contributor Author

I was impressed just quite how many foldrs I found in the code base 😄.

@simonmar
Copy link
Member

I guess I was going through a foldr-happy phase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants