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

CyclicBuffer optimizations #55

Merged
merged 1 commit into from
Feb 19, 2024

Conversation

wrenge
Copy link
Contributor

@wrenge wrenge commented Feb 18, 2024

  1. Ditch ForEach(Action<T>) because it allocates
  2. Implement Enumerator to support foreach keyword
  3. Implement IEnumerable<T> to support Linq (don't use it though)
  4. In ToArray() copy the whole block of memory (or rather two) instead of copying one by one

@@ -42,11 +46,11 @@ public static long Max(this RcCyclicBuffer<long> source)
return 0;

long maxValue = long.MinValue;
source.ForEach(x =>
foreach (var x in source)
{
if (x > maxValue)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Better use Math.Max to avoid branching
Also SIMD is applicable

@@ -27,11 +31,11 @@ public static long Min(this RcCyclicBuffer<long> source)
return 0;

long minValue = long.MaxValue;
source.ForEach(x =>
foreach (var x in source)
{
if (x < minValue)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Better use Math.Min to avoid branching
Also SIMD is applicable

@ikpil ikpil changed the base branch from main to pr/cyclicbuffer-opts February 19, 2024 16:16
@ikpil ikpil merged commit 097a365 into ikpil:pr/cyclicbuffer-opts Feb 19, 2024
2 checks passed
@ikpil
Copy link
Owner

ikpil commented Feb 19, 2024

merged!
thank you!

@wrenge wrenge deleted the pr/cyclicbuffer-opts branch February 20, 2024 11:02
@wrenge wrenge restored the pr/cyclicbuffer-opts branch February 20, 2024 11:02
@wrenge wrenge deleted the pr/cyclicbuffer-opts branch February 20, 2024 11:08
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