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

Try to improve performances #30

Merged
merged 4 commits into from
Sep 4, 2022
Merged

Conversation

MagnaboscoL
Copy link
Contributor

@MagnaboscoL MagnaboscoL commented Sep 3, 2022

This PR tries to improve the performances without altering the API of the package.

The main improvements are:

  • avoid allocating an Element when iterating using (*Element).Next() and (*Element).Prev()
  • avoid allocating an Element when calling (*OrderedMap).Front() and (*OrderedMap).Back()
  • avoid computing the length of the doubly linked list since it is not strictly needed

I guess this PR somehow addresses the concerns expressed in #3 for the v2 version.
benckmarks_pre_PR.txt
benckmarks_post_PR.txt: after commit 1743bc4
benckmarks_post_PR_non_circular_list.txt: after commit 4dccd44


This change is Reviewable

Notes:
- avoid allocating an Element when iterating using (*Element).Next() and (*Element).Prev()
- avoid allocating an Element when calling (*OrderedMap).Front() and (*OrderedMap).Back()
- avoid computing the length of the doubly linked list since it is not strictly needed
Advantages:
- no need of (*Element).list field: save both memory and assignations
- avoid comparisons in (*Element).Next() and (*Element).Prev(): save time
- allow implicit initialization: style
- avoid comparisons in (*list).Front() and (*list).Back(): save time
- keep almost the same execution time for (*list).Remove(), (*list).PushFront() and (*list).PushBack()
Copy link
Owner

@elliotchance elliotchance left a comment

Choose a reason for hiding this comment

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

This is great work! Thank you

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