Skip to content

Optimize scanr for improved performance #29

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

Merged
merged 1 commit into from
Apr 2, 2024

Conversation

usefulmove
Copy link
Contributor

This pull request addresses the TODO comment in the code to further optimize the scanr algorithm. The function has been refactored to run foldl on a reversed version of the input list, rather than use foldr as did the previous implementation. The optimized version also makes use of cons to add to the accumulator list, rather than call convert the added element to a separate list and using append.

The performance analysis detail is below. The test was performed by calling the scanr function on a 2,000,000 element list for 50 cycles.

  • original scanr: CPU Time: 20,720 ms | Real Time: 20,733 ms | GC Time: 15,265 ms
  • optimized scanr: CPU Time: 4,226 ms | Real Time: 4,231 ms | GC Time: 2,701 ms

All raco unit tests have been run successfully.

Note: The original implementation made use of the first function. The testing showed that this increased execution time by about 26%. However, I want to acknowledge that there may be a reason that this is preferred that I am not aware of. I believe the difference is due to first implementing a guard to ensure it is only called on lists while car is missing the same guard.

Please do with this request as you like. I am a fan of this library, and I was hoping to help.

@codereport
Copy link
Owner

@usefulmove This looks great! Are you able to rebase on master / target it to master? It looks like you are targeting a "open-issues" branch from long time ago.

@usefulmove
Copy link
Contributor Author

usefulmove commented Apr 2, 2024 via email

@usefulmove usefulmove changed the base branch from open-issues to master April 2, 2024 17:32
@usefulmove
Copy link
Contributor Author

Yes, of course. I'll do that today. - Duane -

On Tue, Apr 2, 2024 at 7:36 AM Conor Hoekstra @.> wrote: @usefulmove https://github.com/usefulmove This looks great! Are you able to rebase on master / target it to master? It looks like you are targeting a "open-issues" branch from long time ago. — Reply to this email directly, view it on GitHub <#29 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/APO5WT2A6P2QO7FMBGBMRSLY3K67HAVCNFSM6AAAAABFSRSVNGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZSGIYTMOJVGA . You are receiving this because you were mentioned.Message ID: @.>

The pull request should now target master.

Copy link
Owner

@codereport codereport left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 👍

@codereport codereport merged commit 198512b into codereport:master Apr 2, 2024
@usefulmove usefulmove deleted the develop branch April 3, 2024 04:49
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