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

Optimize for common usage with libp2p #59

Open
marcus-pousette opened this issue Apr 28, 2023 · 1 comment
Open

Optimize for common usage with libp2p #59

marcus-pousette opened this issue Apr 28, 2023 · 1 comment

Comments

@marcus-pousette
Copy link
Contributor

marcus-pousette commented Apr 28, 2023

In many cases for the libp2p packages this lib is only used for the cases when N = 1, and the flow is usually "append" -> "sublist" -> "consume". Usually, also, the array only contains 1 element.

So

1). Append
Initialize the empty array in the constructur, and append 1 element to it

2). Sublist
Aquire a sublist which is in many cases just a shallow copy of this array

3). Consume
Make the array empty again


If this lib instead of utilize an linked list instead, we could in theory get overall better performance.

1). Append
On appending the first element, the head is set to the first element

2).
A shallow copy

3).
set the head and tail to be undefined

We could do even better, if we combine 2 and 3 into one method called "splice", we can cut the linked list at an appropriate place, which means that we will do much less operations.

@marcus-pousette
Copy link
Contributor Author

Doing some testing locally,

For a benchmark where we only append 1 element

I can achieve

9.7m ops/s with linked list
7.9m ops/s with the current solution

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

No branches or pull requests

1 participant