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

Feature: Customize spread to maintain bigger emptiness in the rank ends. #195

Closed
wants to merge 2 commits into from

Conversation

cpb
Copy link

@cpb cpb commented Feb 3, 2023

Co-authored-by: Frysch anders.fryksborn@gmail.com
Co-authored-by: Caleb Buxton caleb.buxton@babylist.com

Rebases the preferred_spread Feature atop of the latest:

Requesting Clarification:

I'm still totally keen to solve this problem. Equal spacing really doesn't work when things are always appended to the end of the list. It's an exponential problem by the looks. The list can only be folded so many times before running out of accuracy. I still like the idea of using some kind of sub-spacing per my message above, but I get a gut feeling this might also suffer from the same problem eventually but it certainly won't cause problems with appending where list items don't often get shuffled.

I've added test coverage that illustrates rebalancing during adds.

This is an opt-in feature, so there isn't impact on the cases the original implementation is optimized for … which is to say: very few additions, and quite a lot of reordering.

While the maximum integer available in MySQL is a rather large number, its log2 isn't. The strategy provided by @frysch supports flexible allocation of the MySQL maximum integer space, so users can tune it to their use case.

cpb and others added 2 commits February 2, 2023 13:38
Co-authored-by: Frysch <anders.fryksborn@gmail.com>
Co-authored-by: Caleb Buxton <caleb.buxton@babylist.com>
@cpb cpb mentioned this pull request Feb 3, 2023
Copy link
Owner

@brendon brendon left a comment

Choose a reason for hiding this comment

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

Thanks @cpb, this will be a good addition :) Just a few things to sort :)

modifier = min < max ? 1 : -1

if (max - min).abs < ranker.preferred_spread * 2
rank_at(min + (max - min).abs * 0.3 * modifier)
Copy link
Owner

Choose a reason for hiding this comment

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

Can you walk me through the 0.3? :)

@@ -229,11 +252,13 @@ def rebalance_ranks
gaps = current_order.size + 1
range = (RankedModel::MAX_RANK_VALUE - RankedModel::MIN_RANK_VALUE).to_f
gap_size = (range / gaps).ceil
gap_size = ranker.preferred_spread if ranker.preferred_spread && gap_size > ranker.preferred_spread
base_position = ranker.preferred_spread ? -gap_size * ((current_order.count + 1) / 2).ceil : RankedModel::MIN_RANK_VALUE
Copy link
Owner

Choose a reason for hiding this comment

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

Also a quick explainer of this would be helpful. I'm in a bit of a rush so it'd save me some figuring out time :D

@@ -170,12 +179,26 @@ def update_index_from_position
end
end

def possibly_rebalance_and_position(min, max)
Copy link
Owner

Choose a reason for hiding this comment

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

I think this could be improved in terms of how it's used and reads :) I'll have a think.

@cpb cpb marked this pull request as draft February 7, 2023 17:18
@brendon
Copy link
Owner

brendon commented Jun 4, 2024

@cpb, do you still want to progress this? I'll close it for now, but let me know if you do and I'll re-open it.

@brendon brendon closed this Jun 4, 2024
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.

None yet

2 participants