Skip to content

Eagerly determine when a set is unsortable #3998

Closed

Description

@stevenaw

While trying to optimize collectiontally by pre-sorting items in #3841, an edge case was hit where a Tuple<T1, T2> may implement IComparable even if it's underlying properties didn't. This could cause an exception at runtime. A workaround was done in the PR (#3881) to catch the exception and fallback to a slower path.

#3976 was subsequently filed around an edge-case of this edge-case, where a tuple which has its first property implement IComparable and it's second doesn't could throw an exception at such a point that it left the array in a corrupt state. The workaround in PR #3978 was to copy the array prior to sorting.

We should consider proactively detecting these cases and falling back to the slow path. This will have a few benefits:

  1. Simpler code
  2. Likely lower memory overhead due to not needing to copy the array internally
  3. Better surfacing of issues in calling code by allowing exceptions in user-defined IComparers to halt the comparison entirely

Activity

  1. self-assigned this
    on Nov 27, 2021
  2. changed the title [-]Proactively determine when a set is unsortable[/-] [+]Eagerly determine when a set is unsortable[/+] on Nov 27, 2021
  3. added this to the 3.13.3 milestone on Mar 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions