Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign up`str::contains` is very slow for substring checks #25483
Comments
This comment has been minimized.
This comment has been minimized.
|
StrSearcher has a lot of panic branches that can probably avoided (slicing and unwrapping that will never happen). |
This comment has been minimized.
This comment has been minimized.
|
I wonder wether LLVM can move the comparison out of the loop and if not, why? |
huonw
added
the
I-slow
label
May 16, 2015
This comment has been minimized.
This comment has been minimized.
|
I think this is fundamentally algorithmic problem, since |
This comment has been minimized.
This comment has been minimized.
|
Oh wow, I thought that was something that we had already fixed. |
This comment has been minimized.
This comment has been minimized.
|
The algorithmic problem was fixed, but this fix got disabled in the switch to the pattern API. The two-way search code is still present as dead code. |
This comment has been minimized.
This comment has been minimized.
|
For comparison, I just did a straight translation of a C implementation of BMH. Results for the test in the SO question were:
Where |
alexcrichton
added
the
T-libs
label
May 28, 2015
This comment has been minimized.
This comment has been minimized.
|
triage: I-nominated |
rust-highfive
added
the
I-nominated
label
May 28, 2015
This comment has been minimized.
This comment has been minimized.
|
@DanielKeep Can it be adapted to the pattern API? |
This comment has been minimized.
This comment has been minimized.
|
@bluss I don't see why not; the signature is just (Not that my BMH implementation is likely to be an improvement: it was literally just copy, pasted, and translated from the C reference code. Hell, it uses... indexing. I was in a hurry. :P) |
This comment has been minimized.
This comment has been minimized.
|
Yeah, after implementing the pattern API I haven't found the time to reintegrate the old fast searcher code yet. Part of the issue why I haven't done it directly is that the fast string searcher only supports single ended search, while with the Pattern API you'd want double ended search. One way to resolve this is to just hack the naive and the fast search together into a hybrid that uses the fast search for forward iteration (which is all that happened before anyway), and the naive for backwards iteration, but due to me not fully understanding the fast algorithm I was reluctant to do that as part of the original patch. Wouldn't harm to just do this now and see if any bugs appear though... |
This comment has been minimized.
This comment has been minimized.
|
triage: P-medium |
rust-highfive
added
P-medium
and removed
I-nominated
labels
Jun 1, 2015
This comment has been minimized.
This comment has been minimized.
|
This is allegedly a very interesting improvement upon our two-way search algorithm. http://drops.dagstuhl.de/opus/volltexte/2011/3355/ |
netvl commentedMay 16, 2015
Originally found in SO question.
This Rust code
Executes for up to three minutes on my machine (even with
-C opt-level=3), while the equivalent Ruby or Python code:finishes in several seconds. Java variant finishes almost instantly (but that seems to be due to JIT optimizations).
It looks like that pattern searching for substrings could be severely optimized.