[libcxx-commits] [libcxx] [libc++][ranges] Optimize the performance of `ranges::starts_with` (PR #84570)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Mar 27 09:08:05 PDT 2025
ldionne wrote:
> @ldionne I'm really not sure what to do. It's nice to piggy-back off of the `memcmp` optimizations the compiler can do, which means that we probably cannot compete with some implementations (the compiler can assume more about `memcmp` than it would about our implementation). OTOH we're doing better with our `mismatch` implementation than the system libc in some situations without the optimization barriers that would be required to match `memcmp` on all platforms. From a pure perofrmance stand-point, introducing our own `__memcmp` to be used everywhere instead of the libc one would probably be best. We could replace that with our own implementation if we want (though I fear people will piggy-back off of that for embedded platforms). I'm not sure how the maintainability of that would be though. Would we also introduce our own `memmove` if we can make a faster one?
IMO the answer is that if we can beat the platform's `memcmp` and `memmove`, we should implement our own. And we should also report a bug against any platform that we beat, but we should do it for the sake of libc++'s own performance. In particular, I find it unfortunate that this patch, which should obviously be an improvement, is actually a pessimization due to suboptimal `memcmp` on some platforms. I'd like to be able to unblock patches like this one.
https://github.com/llvm/llvm-project/pull/84570
More information about the libcxx-commits
mailing list