Skip to content

Commit a22cb0f

Browse files
committed
single and multi-threaded index tests (#293)
1 parent 30de988 commit a22cb0f

File tree

10 files changed

+37
-9
lines changed

10 files changed

+37
-9
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ unit-tests: ## run all unit tests
140140
cd git-object && cargo test && cargo test --features verbose-object-parsing-errors
141141
cd git-pack && cargo test --features internal-testing-to-avoid-being-run-by-cargo-test-all \
142142
&& cargo test --features "internal-testing-git-features-parallel"
143+
cd git-index && cargo test --features internal-testing-to-avoid-being-run-by-cargo-test-all \
144+
&& cargo test --features "internal-testing-git-features-parallel"
143145
cd git-packetline && cargo test \
144146
&& cargo test --features blocking-io,maybe-async/is_sync --test blocking-packetline \
145147
&& cargo test --features "async-io" --test async-packetline

etc/check-package-size.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ echo "in root: gitoxide CLI"
1818
#indent cargo diet -n --package-size-limit 25KB - fails right now because of dotted profile.dev.package
1919
(enter cargo-smart-release && indent cargo diet -n --package-size-limit 85KB)
2020
(enter git-actor && indent cargo diet -n --package-size-limit 5KB)
21-
(enter git-index && indent cargo diet -n --package-size-limit 10KB)
21+
(enter git-index && indent cargo diet -n --package-size-limit 15KB)
2222
(enter git-tempfile && indent cargo diet -n --package-size-limit 25KB)
2323
(enter git-lock && indent cargo diet -n --package-size-limit 15KB)
2424
(enter git-config && indent cargo diet -n --package-size-limit 65KB)

git-features/src/parallel/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ pub fn optimize_chunk_size_and_thread_limit(
111111

112112
/// Always returns 1, available when the `parallel` feature toggle is unset.
113113
#[cfg(not(feature = "parallel"))]
114-
fn num_threads(_thread_limit: Option<usize>) -> usize {
114+
pub fn num_threads(_thread_limit: Option<usize>) -> usize {
115115
1
116116
}
117117

118118
/// Returns the amount of threads the system can effectively use as the amount of its logical cores.
119119
///
120120
/// Only available with the `parallel` feature toggle set.
121121
#[cfg(feature = "parallel")]
122-
fn num_threads(thread_limit: Option<usize>) -> usize {
122+
pub fn num_threads(thread_limit: Option<usize>) -> usize {
123123
let logical_cores = num_cpus::get();
124124
thread_limit
125125
.map(|l| if l == 0 { logical_cores } else { l })

git-index/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,22 @@ edition = "2021"
1111
doctest = false
1212
test = true
1313

14+
[[test]]
15+
name = "multi-threaded"
16+
path = "tests/index-multi-threaded.rs"
17+
required-features = ["internal-testing-git-features-parallel"]
18+
19+
[[test]]
20+
name = "single-threaded"
21+
path = "tests/index-single-threaded.rs"
22+
required-features = ["internal-testing-to-avoid-being-run-by-cargo-test-all"]
23+
1424
[features]
1525
serde1 = ["serde"]
1626

27+
internal-testing-git-features-parallel = ["git-features/parallel"]
28+
internal-testing-to-avoid-being-run-by-cargo-test-all = []
29+
1730
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1831

1932
[dependencies]

git-index/src/decode/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct Options {
3737
///
3838
/// This applies to loading extensions in parallel to entries if the common EOIE extension is available.
3939
/// It also allows to use multiple threads for loading entries if the IEOT extension is present.
40-
pub num_threads: Option<usize>,
40+
pub thread_limit: Option<usize>,
4141
/// The minimum size in bytes to load extensions in their own thread, assuming there is enough `num_threads` available.
4242
pub min_extension_block_in_bytes_for_threading: usize,
4343
}
@@ -48,22 +48,24 @@ impl State {
4848
timestamp: FileTime,
4949
Options {
5050
object_hash,
51-
num_threads: _,
51+
thread_limit,
5252
min_extension_block_in_bytes_for_threading: _,
5353
}: Options,
5454
) -> Result<(Self, git_hash::ObjectId), Error> {
5555
let (version, num_entries, post_header_data) = header::decode(data, object_hash)?;
5656
let start_of_extensions = extension::end_of_index_entry::decode(data, object_hash);
5757

58+
let num_threads = git_features::parallel::num_threads(thread_limit);
5859
let path_backing_buffer_size = entries::estimate_path_storage_requirements_in_bytes(
5960
num_entries,
6061
data.len(),
6162
start_of_extensions,
6263
object_hash,
6364
version,
6465
);
66+
6567
let (entries, ext, data) = match start_of_extensions {
66-
Some(offset) => {
68+
Some(offset) if num_threads > 1 => {
6769
let start_of_extensions = &data[offset..];
6870
let index_offsets_table = extension::index_entry_offset_table::find(start_of_extensions, object_hash);
6971
let (entries_res, (ext, data)) = match index_offsets_table {
@@ -89,7 +91,7 @@ impl State {
8991
};
9092
(entries_res?.0, ext, data)
9193
}
92-
None => {
94+
None | Some(_) => {
9395
let (entries, data) = entries::load_all(
9496
post_header_data,
9597
num_entries,

git-index/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,12 @@ pub(crate) mod util {
110110
data.split_at(pos).into()
111111
}
112112
}
113+
114+
#[test]
115+
fn size_of_entry() {
116+
assert_eq!(std::mem::size_of::<crate::Entry>(), 80);
117+
118+
// the reason we have our own time is half the size.
119+
assert_eq!(std::mem::size_of::<crate::entry::Time>(), 8);
120+
assert_eq!(std::mem::size_of::<filetime::FileTime>(), 16);
121+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mod index;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mod index;

git-index/tests/file/mod.rs renamed to git-index/tests/index/file/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod init {
33
use git_testtools::hex_to_id;
44

55
fn file(name: &str) -> git_index::File {
6-
git_index::File::at(crate::index_fixture_path(name), git_index::decode::Options::default()).unwrap()
6+
git_index::File::at(crate::index::fixture_path(name), git_index::decode::Options::default()).unwrap()
77
}
88

99
#[test]

git-index/tests/index.rs renamed to git-index/tests/index/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::path::{Path, PathBuf};
22

33
mod file;
44

5-
pub fn index_fixture_path(name: &str) -> PathBuf {
5+
pub fn fixture_path(name: &str) -> PathBuf {
66
let dir = git_testtools::scripted_fixture_repo_read_only(Path::new("make_index").join(name).with_extension("sh"))
77
.expect("script works");
88
dir.join(".git").join("index")

0 commit comments

Comments
 (0)