Skip to content

Conversation

alexheretic
Copy link
Contributor

@alexheretic alexheretic commented Sep 15, 2025

This PR ports a single ascii fast path optimisation from std str::replace highlighted by benchmarks in #96. I also made it a little more general applying to both StrExt::replace_smolstr & StrExt::replacen_smolstr.

PR bench

group                       faster-1-ascii-replace    master
-----                       ----------------------    ------
replace_smolstr len=12      1.00      6.8±0.03ns      3.51     23.7±0.27ns
replace_smolstr len=50      1.00     29.3±0.05ns      2.84     83.1±0.04ns
replace_smolstr len=1000    1.00    200.2±0.01ns      3.17    635.1±5.58ns

The change provides a significant perf improvement particularly for inline reprs. Also faster than String for len=12 now 🙂 (I measured previously as 10.8ns).

Copy link
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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