Skip to content

Commit 5d905a8

Browse files
Auto merge of #147918 - yotamofek:pr/stringdex-fork, r=<try>
[PERF] see if my fork of `stringdex` affects perf
2 parents 642c19b + bd97748 commit 5d905a8

File tree

4 files changed

+70
-41
lines changed

4 files changed

+70
-41
lines changed

Cargo.lock

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5274,8 +5274,7 @@ dependencies = [
52745274
[[package]]
52755275
name = "stringdex"
52765276
version = "0.0.2"
5277-
source = "registry+https://github.com/rust-lang/crates.io-index"
5278-
checksum = "18b3bd4f10d15ef859c40291769f0d85209de6b0f1c30713ff9cdf45ac43ea36"
5277+
source = "git+https://gitlab.com/yotamofek/stringdex?rev=61a1cda4f942e6a6773e4b969aff7b26903a31f8#61a1cda4f942e6a6773e4b969aff7b26903a31f8"
52795278
dependencies = [
52805279
"stacker",
52815280
]

src/librustdoc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ rustdoc-json-types = { path = "../rustdoc-json-types" }
2121
serde = { version = "1.0", features = ["derive"] }
2222
serde_json = "1.0"
2323
smallvec = "1.8.1"
24-
stringdex = "=0.0.2"
24+
stringdex = { git = "https://gitlab.com/yotamofek/stringdex", rev = "61a1cda4f942e6a6773e4b969aff7b26903a31f8" }
2525
tempfile = "3"
2626
threadpool = "1.8.1"
2727
tracing = "0.1"

src/librustdoc/html/render/search_index.rs

Lines changed: 66 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ mod serde;
33

44
use std::collections::BTreeSet;
55
use std::collections::hash_map::Entry;
6+
use std::io;
67
use std::path::Path;
8+
use std::string::FromUtf8Error;
79

810
use ::serde::de::{self, Deserializer, Error as _};
911
use ::serde::ser::{SerializeSeq, Serializer};
@@ -95,21 +97,28 @@ impl SerializedSearchIndex {
9597
) -> Result<(), Error> {
9698
let root_path = doc_root.join(format!("search.index/root{resource_suffix}.js"));
9799
let column_path = doc_root.join(format!("search.index/{column_name}/"));
100+
101+
struct Consumer<'col>(&'col mut Vec<String>);
102+
103+
impl<'col> stringdex_internals::Consumer for Consumer<'col> {
104+
type Err = FromUtf8Error;
105+
106+
fn consume(&mut self, _id: u32, cell: &[u8]) -> Result<(), Self::Err> {
107+
self.0.push(String::from_utf8(cell.to_vec())?);
108+
Ok(())
109+
}
110+
}
111+
98112
stringdex_internals::read_data_from_disk_column(
99113
root_path,
100114
column_name.as_bytes(),
101115
column_path.clone(),
102-
&mut |_id, item| {
103-
column.push(String::from_utf8(item.to_vec())?);
104-
Ok(())
105-
},
106-
)
107-
.map_err(
108-
|error: stringdex_internals::ReadDataError<Box<dyn std::error::Error>>| Error {
109-
file: column_path,
110-
error: format!("failed to read column from disk: {error}"),
111-
},
116+
&mut Consumer(column),
112117
)
118+
.map_err(|error| Error {
119+
file: column_path,
120+
error: format!("failed to read column from disk: {error}"),
121+
})
113122
}
114123
fn perform_read_serde(
115124
resource_suffix: &str,
@@ -119,25 +128,35 @@ impl SerializedSearchIndex {
119128
) -> Result<(), Error> {
120129
let root_path = doc_root.join(format!("search.index/root{resource_suffix}.js"));
121130
let column_path = doc_root.join(format!("search.index/{column_name}/"));
131+
132+
struct Consumer<'col, T>(&'col mut Vec<Option<T>>);
133+
134+
impl<'col, T> stringdex_internals::Consumer for Consumer<'col, T>
135+
where
136+
T: for<'de> Deserialize<'de> + 'static,
137+
{
138+
type Err = serde_json::Error;
139+
140+
fn consume(&mut self, _id: u32, cell: &[u8]) -> Result<(), Self::Err> {
141+
if cell.is_empty() {
142+
self.0.push(None);
143+
} else {
144+
self.0.push(Some(serde_json::from_slice(cell)?));
145+
}
146+
Ok(())
147+
}
148+
}
149+
122150
stringdex_internals::read_data_from_disk_column(
123151
root_path,
124152
column_name.as_bytes(),
125153
column_path.clone(),
126-
&mut |_id, item| {
127-
if item.is_empty() {
128-
column.push(None);
129-
} else {
130-
column.push(Some(serde_json::from_slice(item)?));
131-
}
132-
Ok(())
133-
},
134-
)
135-
.map_err(
136-
|error: stringdex_internals::ReadDataError<Box<dyn std::error::Error>>| Error {
137-
file: column_path,
138-
error: format!("failed to read column from disk: {error}"),
139-
},
154+
&mut Consumer(column),
140155
)
156+
.map_err(|error| Error {
157+
file: column_path,
158+
error: format!("failed to read column from disk: {error}"),
159+
})
141160
}
142161
fn perform_read_postings(
143162
resource_suffix: &str,
@@ -147,23 +166,30 @@ impl SerializedSearchIndex {
147166
) -> Result<(), Error> {
148167
let root_path = doc_root.join(format!("search.index/root{resource_suffix}.js"));
149168
let column_path = doc_root.join(format!("search.index/{column_name}/"));
169+
170+
struct Consumer<'col>(&'col mut Vec<Vec<Vec<u32>>>);
171+
172+
impl<'col> stringdex_internals::Consumer for Consumer<'col> {
173+
type Err = io::Error;
174+
175+
fn consume(&mut self, _id: u32, cell: &[u8]) -> Result<(), Self::Err> {
176+
let mut postings = Vec::new();
177+
encode::read_postings_from_string(&mut postings, cell);
178+
self.0.push(postings);
179+
Ok(())
180+
}
181+
}
182+
150183
stringdex_internals::read_data_from_disk_column(
151184
root_path,
152185
column_name.as_bytes(),
153186
column_path.clone(),
154-
&mut |_id, buf| {
155-
let mut postings = Vec::new();
156-
encode::read_postings_from_string(&mut postings, buf);
157-
column.push(postings);
158-
Ok(())
159-
},
160-
)
161-
.map_err(
162-
|error: stringdex_internals::ReadDataError<Box<dyn std::error::Error>>| Error {
163-
file: column_path,
164-
error: format!("failed to read column from disk: {error}"),
165-
},
187+
&mut Consumer(column),
166188
)
189+
.map_err(|error| Error {
190+
file: column_path,
191+
error: format!("failed to read column from disk: {error}"),
192+
})
167193
}
168194

169195
assert_eq!(names.len(), path_data.len());
@@ -1059,12 +1085,14 @@ impl Serialize for TypeData {
10591085
let mut buf = Vec::new();
10601086
encode::write_postings_to_string(&self.inverted_function_inputs_index, &mut buf);
10611087
let mut serialized_result = Vec::new();
1062-
stringdex_internals::encode::write_base64_to_bytes(&buf, &mut serialized_result);
1088+
stringdex_internals::encode::write_base64_to_bytes(&buf, &mut serialized_result)
1089+
.unwrap();
10631090
seq.serialize_element(&str::from_utf8(&serialized_result).unwrap())?;
10641091
buf.clear();
10651092
serialized_result.clear();
10661093
encode::write_postings_to_string(&self.inverted_function_output_index, &mut buf);
1067-
stringdex_internals::encode::write_base64_to_bytes(&buf, &mut serialized_result);
1094+
stringdex_internals::encode::write_base64_to_bytes(&buf, &mut serialized_result)
1095+
.unwrap();
10681096
seq.serialize_element(&str::from_utf8(&serialized_result).unwrap())?;
10691097
if self.search_unbox {
10701098
seq.serialize_element(&1)?;

src/tools/tidy/src/extdeps.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const ALLOWED_SOURCES: &[&str] = &[
1111
r#""registry+https://github.com/rust-lang/crates.io-index""#,
1212
// This is `rust_team_data` used by `site` in src/tools/rustc-perf,
1313
r#""git+https://github.com/rust-lang/team#a5260e76d3aa894c64c56e6ddc8545b9a98043ec""#,
14+
// TMP:
15+
r#""git+https://gitlab.com/yotamofek/stringdex?rev=61a1cda4f942e6a6773e4b969aff7b26903a31f8#61a1cda4f942e6a6773e4b969aff7b26903a31f8""#,
1416
];
1517

1618
/// Checks for external package sources. `root` is the path to the directory that contains the

0 commit comments

Comments
 (0)