Skip to content

tsort: remove unnecessary uses of unsafe#13323

Open
mrkalling wants to merge 1 commit into
uutils:mainfrom
mrkalling:remve_unsafe_tsort
Open

tsort: remove unnecessary uses of unsafe#13323
mrkalling wants to merge 1 commit into
uutils:mainfrom
mrkalling:remve_unsafe_tsort

Conversation

@mrkalling

Copy link
Copy Markdown
Contributor

The unsafe code was used to look up values in a hash table without checking whether the values were present. Verifying that a lookup succeeds only requires a few additional instructions, while avoiding unsafe makes the code easier to understand, analyze, and maintain.

If a lookup fails, the program now panics as such a failure indicates a programming error.

The unsafe code was used to look up values in a hash table without
checking whether the values were present. Verifying that a lookup
succeeds only requires a few additional instructions, while avoiding
unsafe makes the code easier to understand, analyze, and maintain.

If a lookup fails, the program now panics. Such a failure indicates a
programming error.
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/date/resolution (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/tail-n0f (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/rm/many-dir-entries-vs-OOM is now being skipped but was previously passing.

@oech3

oech3 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

We should deduplicate validations in the code base instead of duplicationg validation. I don't agree with simply removing unsafe which is logically safe.

@xtqqczze

xtqqczze commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

cc: @anastygnome (as author of #9872)

@mrkalling

Copy link
Copy Markdown
Contributor Author

I would absolutely agree if these unsafe blocks had provided a substantial performance improvement. At best, the unsafe code improves performance by only 0.3%. As I see it, there is still a lot of potential for performance improvements in tsort, and it would be easier to achieve those improvements without using unsafe code.

I've attached my performance measurements, collected with Callgrind, for both the safe and unsafe implementations.

tsort prfomence.csv

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.

3 participants