Provided #35098 (more precisely f729e17 commit) lands, iterating x.encode_utf8().as_slice() results in considerably better code compared to x.encode_utf8().
One major problem with the EncodeUtf8 iterator is the fact that it uses checked indexing, despite it being obvious this iterator cannot index out-of-bounds. However, even if that problem is fixed, noticeably worse code is still generated, but I couldn’t exactly pinpoint why.
cc @alexcrichton #32204