Skip to content

Commit

Permalink
cargo: nuke 'simd-accel' from orbit
Browse files Browse the repository at this point in the history
This feature causes nothing but problems and is frequently broken. The
only optimization it was enabling were SIMD optimizations for
transcoding. In particular, for UTF-16 transcoding. This is performed by
the [`encoding_rs`](https://github.com/hsivonen/encoding_rs) crate,
which specifically uses unstable portable SIMD APIs instead of the
stable non-portable SIMD APIs.

SIMD optimizations that apply to search have long been making use of
stable APIs, and are automatically enabled when your target supports
them. This is, IMO, the correct user experience and one that
`encoding_rs` refuses to support. I'm done dealing with it, so
transcoding will only use scalar code until the SIMD optimizations in
`encoding_rs` work on stable. (This doesn't mean that `encoding_rs` has
to change. This could also be fixed by stabilizing `std::simd`.)

Fixes #2748
  • Loading branch information
BurntSushi committed Mar 7, 2024
1 parent 9bd30e8 commit e9abbc1
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 57 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,11 @@ TBD
===
Unreleased changes. Release notes have not yet been written.

Miscellaneous:

* [MISC #2748](https://github.com/BurntSushi/ripgrep/issues/2748):
Remove ripgrep's `simd-accel` feature because it was frequently broken.


14.1.0 (2024-01-06)
===================
Expand Down
33 changes: 0 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Expand Up @@ -68,7 +68,6 @@ serde_derive = "1.0.77"
walkdir = "2"

[features]
simd-accel = ["grep/simd-accel"]
pcre2 = ["grep/pcre2"]

[profile.release]
Expand Down
22 changes: 7 additions & 15 deletions README.md
Expand Up @@ -432,18 +432,13 @@ $ ./target/release/rg --version
0.1.3
```

If you have a Rust nightly compiler and a recent Intel CPU, then you can enable
additional optional SIMD acceleration like so:

```
RUSTFLAGS="-C target-cpu=native" cargo build --release --features 'simd-accel'
```

The `simd-accel` feature enables SIMD support in certain ripgrep dependencies
(responsible for transcoding). They are not necessary to get SIMD optimizations
for search; those are enabled automatically. Hopefully, some day, the
`simd-accel` feature will similarly become unnecessary. **WARNING:** Currently,
enabling this option can increase compilation times dramatically.
**NOTE:** In the past, ripgrep supported a `simd-accel` Cargo feature when
using a Rust nightly compiler. This only benefited UTF-16 transcoding.
Since it required unstable features, this build mode was prone to breakage.
Because of that, support for it has been removed. If you want SIMD
optimizations for UTF-16 transcoding, then you'll have to petition the
[`encoding_rs`](https://github.com/hsivonen/encoding_rs) project to use stable
APIs.

Finally, optional PCRE2 support can be built with ripgrep by enabling the
`pcre2` feature:
Expand All @@ -452,9 +447,6 @@ Finally, optional PCRE2 support can be built with ripgrep by enabling the
$ cargo build --release --features 'pcre2'
```

(Tip: use `--features 'pcre2 simd-accel'` to also include compile time SIMD
optimizations, which will only work with a nightly compiler.)

Enabling the PCRE2 feature works with a stable Rust compiler and will
attempt to automatically find and link with your system's PCRE2 library via
`pkg-config`. If one doesn't exist, then ripgrep will build PCRE2 from source
Expand Down
3 changes: 0 additions & 3 deletions crates/core/flags/doc/version.rs
Expand Up @@ -161,9 +161,6 @@ fn compile_cpu_features() -> Vec<String> {
fn features() -> Vec<String> {
let mut features = vec![];

let simd_accel = cfg!(feature = "simd-accel");
features.push(format!("{sign}simd-accel", sign = sign(simd_accel)));

let pcre2 = cfg!(feature = "pcre2");
features.push(format!("{sign}pcre2", sign = sign(pcre2)));

Expand Down
4 changes: 2 additions & 2 deletions crates/grep/Cargo.toml
Expand Up @@ -26,8 +26,8 @@ termcolor = "1.0.4"
walkdir = "2.2.7"

[features]
simd-accel = ["grep-searcher/simd-accel"]
pcre2 = ["grep-pcre2"]

# This feature is DEPRECATED. Runtime dispatch is used for SIMD now.
# These features are DEPRECATED. Runtime dispatch is used for SIMD now.
simd-accel = []
avx-accel = []
5 changes: 2 additions & 3 deletions crates/searcher/Cargo.toml
Expand Up @@ -27,7 +27,6 @@ grep-regex = { version = "0.1.12", path = "../regex" }
regex = "1.9.5"

[features]
simd-accel = ["encoding_rs/simd-accel"]

# This feature is DEPRECATED. Runtime dispatch is used for SIMD now.
# These features are DEPRECATED. Runtime dispatch is used for SIMD now.
simd-accel = []
avx-accel = []

0 comments on commit e9abbc1

Please sign in to comment.