Skip to content

Clean up unreachable_unchecked #1276

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Manishearth
Copy link

No description provided.

@dtolnay
Copy link
Member

dtolnay commented Jul 29, 2025

I would like to understand #1275 before landing any workaround. Was the unreachable_unchecked not actually unreachable? If there is a compiler bug has that been minimized and reported?

@Manishearth
Copy link
Author

@dtolnay to be clear, I haven't investigated that at all: I came across this during unsafe review and didn't think the unsafe was necessary here.

@Manishearth
Copy link
Author

Manishearth commented Jul 29, 2025

I think this removes some unsafe in a way that ought not affect performance, and that makes it a good change on its own. It's not a workaround.

I do not have access to the code in #1275 and cannot debug it. They are welcome to apply this patch and see if it changes anything. I suspect it won't, I suspect their leak comes from elsewhere.

@dtolnay
Copy link
Member

dtolnay commented Jul 29, 2025

I think this removes some unsafe in a way that ought not affect performance

Based on the benchmark in the PR that introduced this code, on my machines this PR regresses serialization performance by 22% (2990WX) or 51% (M4 Max).

@Manishearth
Copy link
Author

Oh, hm. That's not good.

I'm pretty sure this code can be written without the unreachable, but perhaps my way of doing it has a problem. Either the char_escape match is broken, or the array indexing-and-match introduces an additional branch, is my guess.

@Manishearth
Copy link
Author

Alternate idea: we stick a debug_assert! there and then use a continue or something.

@aweiker
Copy link

aweiker commented Jul 29, 2025

I'm working on an isolate repro scenario however I've been so busy with work that I haven't had time to get anywhere yet. Reading the docs on uncreachable_unchecked it makes me nervous and also very easy to see why in our use case it's likely something that hasn't had a lot of testing put into place. We are compiling to WASM and running this code as a plugin to Envoy. My assumption is that most of the performance/regression testing is is done platform specific code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants