Skip to content

Conversation

@alexheretic
Copy link
Contributor

Optimisation opportunity highlighted by testing against String perf and using benchmarks in #96.

This is slightly more involved than the ascii optimisations in #97. I ported std convert_while_ascii into an inline version inline_convert_while_ascii to get an equivalent ascii-optimistic optimisation to the String version.

PR bench

group                                  master                  faster-case
-----                                  ------                  -----------
to_lowercase_smolstr len=12            2.13     65.3±0.20ns    1.00     30.7±0.03ns
to_lowercase_smolstr len=50            5.70    354.6±0.43ns    1.00     62.2±0.03ns
to_lowercase_smolstr len=1000          52.06     5.8±0.01µs    1.00    111.6±0.06ns

The change provides a significant perf improvement on inline & heap reprs. Also faster than String for len=12 now 🙂.

The benchmark is favourable to this optimisation as it measures a string with mostly ascii prefix. But I think this is a very common case for this method so the optimisation makes sense generally, and clearly std think so too.

@alexheretic
Copy link
Contributor Author

@Veykril any issues with this? It would be nice to get these, and the other pr, improvements into a new smol_str release.

@Veykril
Copy link
Member

Veykril commented Oct 11, 2025

Ah sorry, forgot about this, I'll try to get back to this + do a release the coming week as I am a bit busy right now (if I'm not coming back to this this week please aggressively re-ping me)

@alexheretic
Copy link
Contributor Author

@Veykril just a reminder it would be nice to have this + #100 in a new release, please review when you have some time & let me know if you have issues/concerns.

Also #96 benches may aid future optimisations (as they did this pr) so perhaps worth merging too.

@Veykril
Copy link
Member

Veykril commented Oct 22, 2025

I threw you a collaborator invite, so go ahead and rebase and merge the other PRs. I'll do a release when the other PRs are merged then.

@alexheretic alexheretic merged commit 08a9dc8 into rust-analyzer:master Oct 22, 2025
1 check passed
@alexheretic alexheretic deleted the faster-case branch October 22, 2025 13:25
@alexheretic
Copy link
Contributor Author

I threw you a collaborator invite, so go ahead and rebase and merge the other PRs. I'll do a release when the other PRs are merged then.

All merged now, thanks!

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.

2 participants