Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add memmem implementation, upgrade to Rust 2018, bump MSRV to Rust 1.41.1 #82

Merged
merged 4 commits into from
Apr 30, 2021

Conversation

BurntSushi
Copy link
Owner

This commit primarily adds vectorized substring search routines in
a new memmem sub-module. They were originally taken from bstr, but
heavily modified to incorporate a variant of the "generic SIMD"
algorithm[1]. The main highlights:

  • We guarantee O(m + n) time complexity and constant space
    complexity.
  • Two-Way is the primary implementation that can handle all cases.
  • Vectorized variants handle a number of common cases.
  • Vectorized code uses a heuristic informed by a frequency background
    distribution of bytes, originally devised inside the regex crate.
    This makes it more likely that searching will spend more time in the
    fast vector loops.

While adding memmem to this crate is perhaps a bit of a scope increase,
I think it fits well. It also puts a core primitive, substring
search, very low in the dependency DAG and therefore making it widely
available. For example, it is intended to use these new routines in the
regex, aho-corasick and bstr crates.

This commit does a number of other things, mainly as a result of
convenience. It drastically improves test coverage for substring search
(as compared to what bstr had), completely overhauls the benchmark suite
to make it more comprehensive and adds cargo fuzz support for all API
items in the crate.

[1] - http://0x80.pl/articles/simd-strfind.html#algorithm-1-generic-simd

This was long overdue, but I had been busy with other things.

This also bumps the MSRV to Rust 1.41, which is what is currently in
Debian stable.
This basically bumps down all of the memchr tests/benchmarks into a
sub-module in order to make room for tests/benchmarks for other APIs
like memmem.
@BurntSushi BurntSushi force-pushed the ag/memmem branch 3 times, most recently from 7865405 to d5cfcca Compare April 30, 2021 11:05
@BurntSushi BurntSushi force-pushed the ag/memmem branch 4 times, most recently from 317075f to 7810d6c Compare April 30, 2021 18:09
BurntSushi added a commit to rust-lang/regex that referenced this pull request Apr 30, 2021
This was long overdue, and we were motivated by memchr's move to Rust
2018 in BurntSushi/memchr#82.

Rust 1.41.1 was selected because it's the current version of Rust in
Debian Stable. It also feels old enough to assure wide support.
BurntSushi added a commit to BurntSushi/aho-corasick that referenced this pull request Apr 30, 2021
This is in line with similar changes to the regex and memchr crates:
BurntSushi/memchr#82
and
rust-lang/regex#767
This commit primarily adds vectorized substring search routines in
a new memmem sub-module. They were originally taken from bstr, but
heavily modified to incorporate a variant of the "generic SIMD"
algorithm[1]. The main highlights:

* We guarantee `O(m + n)` time complexity and constant space
  complexity.
* Two-Way is the primary implementation that can handle all cases.
* Vectorized variants handle a number of common cases.
* Vectorized code uses a heuristic informed by a frequency background
  distribution of bytes, originally devised inside the regex crate.
  This makes it more likely that searching will spend more time in the
  fast vector loops.

While adding memmem to this crate is perhaps a bit of a scope increase,
I think it fits well. It also puts a core primitive, substring
search, very low in the dependency DAG and therefore making it widely
available. For example, it is intended to use these new routines in the
regex, aho-corasick and bstr crates.

This commit does a number of other things, mainly as a result of
convenience. It drastically improves test coverage for substring search
(as compared to what bstr had), completely overhauls the benchmark suite
to make it more comprehensive and adds `cargo fuzz` support for all API
items in the crate.

Closes #58, Closes #72

[1] - http://0x80.pl/articles/simd-strfind.html#algorithm-1-generic-simd
This makes it easy to link to benchmarks when someone asks, but also
serves as a good way to archive benchmark data at defined points for
comparison later.

We also make a (feeble) attempt at putting a "pretty" version of a
subset of benchmarks in the README of each run directory.
@BurntSushi BurntSushi merged commit ffb8d99 into master Apr 30, 2021
@BurntSushi BurntSushi deleted the ag/memmem branch April 30, 2021 23:23
BurntSushi added a commit to BurntSushi/aho-corasick that referenced this pull request Apr 30, 2021
This is in line with similar changes to the regex and memchr crates:
BurntSushi/memchr#82
and
rust-lang/regex#767
BurntSushi added a commit to rust-lang/regex that referenced this pull request Apr 30, 2021
This was long overdue, and we were motivated by memchr's move to Rust
2018 in BurntSushi/memchr#82.

Rust 1.41.1 was selected because it's the current version of Rust in
Debian Stable. It also feels old enough to assure wide support.
BurntSushi added a commit to rust-lang/regex that referenced this pull request Apr 30, 2021
This was long overdue, and we were motivated by memchr's move to Rust
2018 in BurntSushi/memchr#82.

Rust 1.41.1 was selected because it's the current version of Rust in
Debian Stable. It also feels old enough to assure wide support.
BurntSushi added a commit to rust-lang/regex that referenced this pull request May 1, 2021
This was long overdue, and we were motivated by memchr's move to Rust
2018 in BurntSushi/memchr#82.

Rust 1.41.1 was selected because it's the current version of Rust in
Debian Stable. It also feels old enough to assure wide support.
@BurntSushi
Copy link
Owner Author

This PR is on crates.io in memchr 2.4.0.

@hkratz
Copy link

hkratz commented May 2, 2021

Excellent, thanks for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants