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

Refactor: MovingInterquartileMean #13730

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Swiftb0y
Copy link
Member

@Swiftb0y Swiftb0y commented Oct 8, 2024

what was initially just supposed to be a cleanup/refactor, mutated into a full blown optimization. This is primarily intended as a cleanup though, and I only implemented the benchmark to show that this was not causing regressions in performance. There is still a little more to be done, but these are some preliminary numbers.
Before:

-----------------------------------------------------------------------------
Benchmark                   Time             CPU   Iterations UserCounters...
-----------------------------------------------------------------------------
BM_insertion/16         17485 ns        16857 ns            1 items_per_second=3.79664M/s
BM_insertion/64         20922 ns        20926 ns            1 items_per_second=12.2336M/s
BM_insertion/512       774264 ns       770344 ns            1 items_per_second=2.65855M/s
BM_insertion/4096    55161004 ns     54684805 ns            1 items_per_second=299.608k/s
BM_insertion/16384  891138337 ns    886767771 ns            1 items_per_second=73.9044k/s

After:

-----------------------------------------------------------------------------
Benchmark                   Time             CPU   Iterations UserCounters...
-----------------------------------------------------------------------------
BM_insertion/16         10458 ns         9738 ns            1 items_per_second=6.57219M/s
BM_insertion/64         16030 ns        15969 ns            1 items_per_second=16.0311M/s
BM_insertion/512       745585 ns       735096 ns            1 items_per_second=2.78603M/s
BM_insertion/4096    40907286 ns     40517411 ns            1 items_per_second=404.369k/s
BM_insertion/16384  644210901 ns    641245320 ns            1 items_per_second=102.201k/s

@Swiftb0y Swiftb0y changed the title Refactor: MovingInterquartileMean optimization Refactor: MovingInterquartileMean refactor Oct 8, 2024
@Swiftb0y Swiftb0y force-pushed the refactor/moving-iqm-optimization branch from a274651 to c35a86c Compare October 8, 2024 21:08
@Swiftb0y
Copy link
Member Author

Swiftb0y commented Oct 8, 2024

So I added yet another optimization (custom replace_sorted algorithm instead of erase+insert) which adds further speedups, especially with realistic IQM sizes.

Edit: Just realized that the Y-Label is not quite right, its "elements processed per second".

MovingIQM Benchmark graph

Please review.

@github-actions github-actions bot added the build label Oct 8, 2024
@Swiftb0y Swiftb0y changed the title Refactor: MovingInterquartileMean refactor Refactor: MovingInterquartileMean Oct 8, 2024
This should also optimize speed and memory usage for small-ish
windows (which is the only usecase right now)
This implements the usecase where you want to replace a value in
a sorted range while keeping the range sorted.
This serves as an efficient alternative to what would otherwise
be an erase followed by an insert, which requires unnecessary
moves.
@Swiftb0y Swiftb0y force-pushed the refactor/moving-iqm-optimization branch from 1bc2bb1 to c4ad157 Compare October 9, 2024 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant