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)

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