Skip to content

[Feature]: Improve ChangeSet emission when a single item moves upwards in index on a Sort #1066

@Chicken-Bones

Description

@Chicken-Bones

Describe the functionality desired 🐞

Currently, if a Sort causes a single item to move from a low index to a high index, instead of generating one single Move change for the given item, the Reorder implementation in Internal/List.cs emits move down by 1 events for every item in the list between the old and new index of the 'moved' item.

I understand that moving one item up n spaces, and moving n items down 1 space are equivalent and symmetric operations, but the stream of change events from each item moving can easily trigger reset thresholds (eg on Bind)

It's an uncomfortable gotcha when a 'single' upstream property change explodes into a stream of N events, and then resets all bound view components due to a list refresh just because it moved more than 25 indices.

I understand this is a well known problem in React as well, just in the opposite direction

I know that finding a minimal sequence of moves is O(n^2), but it should be possible to optimize for the 'single item moved up' case by adding some logic in ChangeAwareList.Move which:

  • Detects 'move down by 1' events (destination == original - 1)
  • Converts them to 'move up by 1' events on the previous item
  • Checks the last entry in _changes. If it is a move up by n event, with last.destination == destination then instead of emitting a new event, convert the last event to 'move up by n+1'

The steps the functionality will provide

Performance optimization and no rest threshold triggered when a single item moves up in index due to a sort.

Considerations

I don't have a checkout of the code available to test my theory. A workaround exists to just set resetThreshold: int.MaxValue but it's a bit uncomfortable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions