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

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

Merged
merged 1 commit into from
Jul 14, 2024

Conversation

rocallahan
Copy link
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
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
16 checks passed
@rocallahan rocallahan deleted the stable-sort branch July 16, 2024 00:46
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