Skip to content

Use std::stable_sort instead of std::sort everywhere#655

Merged
costamag merged 1 commit intolsils:masterfrom
rocallahan:stable-sort
Jul 14, 2024
Merged

Use std::stable_sort instead of std::sort everywhere#655
costamag merged 1 commit intolsils:masterfrom
rocallahan:stable-sort

Conversation

@rocallahan
Copy link
Copy Markdown
Contributor

@rocallahan rocallahan commented Jul 3, 2024

Test results currently depend on how compare-equal elements are sorted by std::sort's unstable sort. Defaulting to std::stable_sort avoids that problem and generally increases the determinism of the code, which is good.

If there are specific cases where the (fairly small) performance overhead of stable sorting is a concern, those can be switched back to unstable sorting as an optimization, but first one would need to verify that that doesn't break the tests (e.g., by running the tests with a shuffle before each call to unstable sort).

Resolves #654

Test results currently depend on how compare-equal elements are sorted
by `std::sort`'s`unstable sort. Defaulting to `std::stable_sort` avoids
that problem and generally increases the determinism of the code, which
is good.

If there are specific cases where the (fairly small) performance
overhead of stable sorting is a concern, those can be switched back
to unstable sorting as an optimization, but first one would need to
verify that that doesn't break the tests (e.g., by running the tests
with a shuffle before each call to unstable sort).

Resolves lsils#654
@costamag costamag self-assigned this Jul 11, 2024
@costamag
Copy link
Copy Markdown
Contributor

Verified no significant performance degradation in the experiments when doing the suggested replacement.
Thank you for identifying this source of non-determinism!

@costamag costamag merged commit ebf35c2 into lsils:master Jul 14, 2024
@rocallahan rocallahan deleted the stable-sort branch July 16, 2024 00:46
costamag pushed a commit to costamag/mockturtle that referenced this pull request Dec 15, 2025
Test results currently depend on how compare-equal elements are sorted
by `std::sort`'s`unstable sort. Defaulting to `std::stable_sort` avoids
that problem and generally increases the determinism of the code, which
is good.

If there are specific cases where the (fairly small) performance
overhead of stable sorting is a concern, those can be switched back
to unstable sorting as an optimization, but first one would need to
verify that that doesn't break the tests (e.g., by running the tests
with a shuffle before each call to unstable sort).

Resolves lsils#654
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.

Test results depend on the order of compare-equal elements in unstable sort

2 participants