Skip to content
Myr

ignore,globset: increase pool capacity

Before adoption: this commit came in with the history the project adopted, so no landing records it.

When do matching inside of `ignore` or `globset`, we sometimes need a reusable mutable scratch space for matching. To do this, we use a `Pool` abstraction from `regex-automata` to do this heavy lifting for us. It turns out that this can be a limiting factor in some scenarios when gitignore matching dominates. For example, in my checkout of the Chromium repository: ``` $ hyperfine 'rg-master -j32 --files' 'rg-bigger-pool -j32 --files' 'rg-master -j32 --files --no-ignore' Benchmark 1: rg-master -j32 --files Time (mean ± σ): 156.3 ms ± 5.5 ms [User: 2356.4 ms, System: 380.8 ms] Range (min … max): 147.6 ms … 164.5 ms 19 runs Benchmark 2: rg-bigger-pool -j32 --files Time (mean ± σ): 131.6 ms ± 2.1 ms [User: 1628.2 ms, System: 310.1 ms] Range (min … max): 128.8 ms … 136.3 ms 22 runs Benchmark 3: rg-master -j32 --files --no-ignore Time (mean ± σ): 107.4 ms ± 1.0 ms [User: 664.7 ms, System: 304.7 ms] Range (min … max): 104.9 ms … 109.6 ms 28 runs Summary rg-master -j32 --files --no-ignore ran 1.22 ± 0.02 times faster than rg-bigger-pool -j32 --files 1.45 ± 0.05 times faster than rg-master -j32 --files ``` The `--no-ignore` benchmark is our baseline. It doesn't process gitignore files, so it's quite a bit faster. But with this change, processing gitignore files gets faster than what is currently on master. Specifically, re-running the above without the baseline: ``` $ hyperfine 'rg-master -j32 --files' 'rg-bigger-pool -j32 --files' Benchmark 1: rg-master -j32 --files Time (mean ± σ): 154.1 ms ± 5.1 ms [User: 2287.4 ms, System: 378.2 ms] Range (min … max): 144.1 ms … 163.9 ms 19 runs Benchmark 2: rg-bigger-pool -j32 --files Time (mean ± σ): 131.7 ms ± 2.1 ms [User: 1618.6 ms, System: 314.1 ms] Range (min … max): 128.4 ms … 135.3 ms 22 runs Summary rg-bigger-pool -j32 --files ran 1.17 ± 0.04 times faster than rg-master -j32 --files ``` I've used `-j32` here because this change is best observed as improving the *scaling* properties. (And my system has 32 cores, so it's the best case scenario.) If we just let ripgrep use its default thread heuristic (which caps itself at a lower value), then the improvement here is a bit more modest: ``` $ hyperfine 'rg-master --files' 'rg-bigger-pool --files' Benchmark 1: rg-master --files Time (mean ± σ): 150.0 ms ± 8.5 ms [User: 1139.6 ms, System: 237.7 ms] Range (min … max): 131.1 ms … 162.4 ms 22 runs Benchmark 2: rg-bigger-pool --files Time (mean ± σ): 136.0 ms ± 12.1 ms [User: 1034.4 ms, System: 236.0 ms] Range (min … max): 117.7 ms … 157.6 ms 22 runs Summary rg-bigger-pool --files ran 1.10 ± 0.12 times faster than rg-master --files ``` This improves scaling because the underlying change here now uses a cache line for each available thread instead of limiting itself to a fixed value of `8`. The cost is that ripgrep may use a bit more memory storing cached values per thread.

authored by Andrew Gallant · committed by Andrew Gallant · parent 7525479 · Browse files · 5 files+52 added−35 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+52 added−35 removed

  • other:+52 added−35 removed

5 files+52 added−35 removed

modified:crates/globset/Cargo.toml+1 added-1 removed
modified:crates/ignore/src/gitignore.rs+3 added-1 removed
357 unmodified lines
358 root: self.root.clone(),359 globs: self.globs.clone(),360 num_ignores: nignore as u64,361 num_whitelists: nwhite as u64,362 matches: Some(Arc::new(Pool::new(|| vec![]))),362 matches: Some(Arc::new(363 Pool::with_available_parallelism_capacity(|| vec![]),364 )),365 })366 }367368 /// Build a global gitignore matcher using the configuration in this
517 unmodified lines
modified:crates/ignore/src/types.rs+6 added-2 removed
229 unmodified lines
230 selections: vec![],231 has_selected: false,232 glob_to_selection: vec![],233 set: GlobSetBuilder::new().build().unwrap(),234 matches: Arc::new(Pool::new(|| vec![])),234 matches: Arc::new(Pool::with_available_parallelism_capacity(235 || vec![],236 )),237 }238 }239240 /// Returns true if and only if this matcher has zero selections.
117 unmodified lines
358 selections,359 has_selected,360 glob_to_selection,361 set,360 matches: Arc::new(Pool::new(|| vec![])),362 matches: Arc::new(Pool::with_available_parallelism_capacity(363 || vec![],364 )),365 })366 }367368 /// Return the set of current file type definitions.
220 unmodified lines
modified:crates/ignore/Cargo.toml+1 added-1 removed
modified:Cargo.lock+41 added-30 removed
2 unmodified lines
3version = 445[[package]]6name = "aho-corasick"7version = "1.1.4"7version = "1.1.5"8source = "registry+https://github.com/rust-lang/crates.io-index"9checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"9checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba"10dependencies = [11 "memchr",12]1314[[package]]15name = "anyhow"16version = "1.0.103"16version = "1.0.104"17source = "registry+https://github.com/rust-lang/crates.io-index"18checksum = "2a4385e2e34eb35d6b3efe798b9eb88096925d87726c0798709bf56d9ed84af3"18checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"1920[[package]]21name = "arbitrary"22version = "1.4.2"
15 unmodified lines
38]3940[[package]]41name = "cc"42version = "1.2.67"42version = "1.4.0"43source = "registry+https://github.com/rust-lang/crates.io-index"44checksum = "e17dd265a7d0f31ef544e1b20e03add05d3b45b491b633b10d67145d2acc1a38"44checksum = "5add81bb678e6cb321aff7fa0dc7689ad82b112dbc032cea19f91d6b8e3582b9"45dependencies = [46 "find-msvc-tools",47 "jobserver",48 "libc",
47 unmodified lines
96checksum = "1e567bd82dcff979e4b03460c307b3cdc9e96fde3d73bed1496d2bc75d9dd62a"97dependencies = [98 "proc-macro2",99 "quote",100 "syn",100 "syn 2.0.119",101]102103[[package]]104name = "encoding_rs"
5 unmodified lines
110]111112[[package]]113name = "encoding_rs_io"114version = "0.1.7"114version = "0.1.8"115source = "registry+https://github.com/rust-lang/crates.io-index"116checksum = "1cc3c5651fb62ab8aa3103998dade57efdd028544bd300516baa31840c252a83"116checksum = "fba3fe847045ecff794b9c138293a80db914678c453ad63fbf0c6a9eb6e00b22"117dependencies = [118 "encoding_rs",119]120
21 unmodified lines
142]143144[[package]]145name = "glob"146version = "0.3.3"146version = "0.3.4"147source = "registry+https://github.com/rust-lang/crates.io-index"148checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"148checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b"149150[[package]]151name = "globset"152version = "0.4.19"
142 unmodified lines
295checksum = "803ec87c9cfb29b9d2633f20cba1f488db3fd53f2158b1024cbefb47ba05d413"296297[[package]]298name = "libc"299version = "0.2.186"299version = "0.2.189"300source = "registry+https://github.com/rust-lang/crates.io-index"301checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"301checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"302303[[package]]304name = "log"305version = "0.4.33"
44 unmodified lines
350checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e"351352[[package]]353name = "proc-macro2"354version = "1.0.106"354version = "1.0.107"355source = "registry+https://github.com/rust-lang/crates.io-index"356checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"356checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"357dependencies = [358 "unicode-ident",359]360361[[package]]362name = "quote"363version = "1.0.46"363version = "1.0.47"364source = "registry+https://github.com/rust-lang/crates.io-index"365checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368"365checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"366dependencies = [367 "proc-macro2",368]369
13 unmodified lines
383]384385[[package]]386name = "regex"387version = "1.13.0"387version = "1.13.1"388source = "registry+https://github.com/rust-lang/crates.io-index"389checksum = "2a0e75113e14dc5acb068cd0786884f214f1312650a3d36d269f5c4f3cdee8a2"389checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d"390dependencies = [391 "aho-corasick",392 "memchr",393 "regex-automata",
1 unmodified line
395]396397[[package]]398name = "regex-automata"399version = "0.4.15"399version = "0.4.18"400source = "registry+https://github.com/rust-lang/crates.io-index"401checksum = "1f388202e4b80542a0921078cc23b6333bcf1409c1e3f86404cae4766a6131db"401checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2"402dependencies = [403 "aho-corasick",404 "memchr",405 "regex-syntax",
35 unmodified lines
441]442443[[package]]444name = "serde"445version = "1.0.228"445version = "1.0.229"446source = "registry+https://github.com/rust-lang/crates.io-index"447checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"447checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"448dependencies = [449 "serde_core",450]451452[[package]]453name = "serde_core"454version = "1.0.228"454version = "1.0.229"455source = "registry+https://github.com/rust-lang/crates.io-index"456checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"456checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"457dependencies = [458 "serde_derive",459]460461[[package]]462name = "serde_derive"463version = "1.0.228"463version = "1.0.229"464source = "registry+https://github.com/rust-lang/crates.io-index"465checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"465checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"466dependencies = [467 "proc-macro2",468 "quote",469 "syn",469 "syn 3.0.3",470]471472[[package]]473name = "serde_json"474version = "1.0.150"474version = "1.0.151"475source = "registry+https://github.com/rust-lang/crates.io-index"476checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9"476checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14"477dependencies = [478 "itoa",479 "memchr",480 "serde",
18 unmodified lines
499 "unicode-ident",500]501502[[package]]503name = "syn"504version = "3.0.3"505source = "registry+https://github.com/rust-lang/crates.io-index"506checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3"507dependencies = [508 "proc-macro2",509 "quote",510 "unicode-ident",511]512513[[package]]514name = "termcolor"515version = "1.4.1"516source = "registry+https://github.com/rust-lang/crates.io-index"517checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755"
75 unmodified lines