Skip to content

Commit af00ff2

Browse files
committed
Auto merge of #145911 - notriddle:stringdex-tweak-3, r=GuillaumeGomez
rustdoc-search: yet another stringdex optimization attempt This one's uses a different tactic. It shouldn't significantly increase the amount of downloaded index data, but still reduces the amount of disk usage. This one works by changing the suffix-only node representation to omit some data that's needed for checking. Since those nodes make up the bulk of the tree, it reduces the data they store, but also requires validating the match by fetching the name itself (but the names list is pretty small, and when I tried it with wordnet "indexing" it was about the same). r? `@GuillaumeGomez`
2 parents 0d6a806 + 80e1805 commit af00ff2

File tree

5 files changed

+647
-164
lines changed

5 files changed

+647
-164
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5152,9 +5152,9 @@ dependencies = [
51525152

51535153
[[package]]
51545154
name = "stringdex"
5155-
version = "0.0.1-alpha4"
5155+
version = "0.0.1-alpha9"
51565156
source = "registry+https://github.com/rust-lang/crates.io-index"
5157-
checksum = "2841fd43df5b1ff1b042e167068a1fe9b163dc93041eae56ab2296859013a9a0"
5157+
checksum = "7081029913fd7d591c0112182aba8c98ae886b4f12edb208130496cd17dc3c15"
51585158
dependencies = [
51595159
"stacker",
51605160
]

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 = { version = "0.0.1-alpha4" }
24+
stringdex = { version = "0.0.1-alpha9" }
2525
tempfile = "3"
2626
threadpool = "1.8.1"
2727
tracing = "0.1"

src/librustdoc/html/static/js/search.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ class DocSearch {
12121212
* will never fulfill.
12131213
*/
12141214
async buildIndex() {
1215-
const nn = this.database.getIndex("normalizedName");
1215+
const nn = this.database.getData("normalizedName");
12161216
if (!nn) {
12171217
return;
12181218
}
@@ -3722,7 +3722,7 @@ class DocSearch {
37223722
* @returns {AsyncGenerator<rustdoc.ResultObject>}
37233723
*/
37243724
async function*(currentCrate) {
3725-
const index = this.database.getIndex("normalizedName");
3725+
const index = this.database.getData("normalizedName");
37263726
if (!index) {
37273727
return;
37283728
}
@@ -3851,8 +3851,7 @@ class DocSearch {
38513851
};
38523852
if (elem.normalizedPathLast === "") {
38533853
// faster full-table scan for this specific case.
3854-
const nameData = this.database.getData("name");
3855-
const l = nameData ? nameData.length : 0;
3854+
const l = index.length;
38563855
for (let id = 0; id < l; ++id) {
38573856
if (!idDuplicates.has(id)) {
38583857
idDuplicates.add(id);
@@ -3954,7 +3953,7 @@ class DocSearch {
39543953
* @returns {AsyncGenerator<rustdoc.ResultObject>}
39553954
*/
39563955
async function*(inputs, output, typeInfo, currentCrate) {
3957-
const index = this.database.getIndex("normalizedName");
3956+
const index = this.database.getData("normalizedName");
39583957
if (!index) {
39593958
return;
39603959
}

src/librustdoc/html/static/js/stringdex.d.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,8 @@ declare namespace stringdex {
55
* The client interface to Stringdex.
66
*/
77
interface Database {
8-
getIndex(colname: string): SearchTree|undefined;
98
getData(colname: string): DataColumn|undefined;
109
}
11-
/**
12-
* A search index file.
13-
*/
14-
interface SearchTree {
15-
trie(): Trie;
16-
search(name: Uint8Array|string): Promise<Trie?>;
17-
searchLev(name: Uint8Array|string): AsyncGenerator<Trie>;
18-
}
1910
/**
2011
* A compressed node in the search tree.
2112
*
@@ -29,9 +20,7 @@ declare namespace stringdex {
2920
matches(): RoaringBitmap;
3021
substringMatches(): AsyncGenerator<RoaringBitmap>;
3122
prefixMatches(): AsyncGenerator<RoaringBitmap>;
32-
keys(): Uint8Array;
3323
keysExcludeSuffixOnly(): Uint8Array;
34-
children(): [number, Promise<Trie>][];
3524
childrenExcludeSuffixOnly(): [number, Promise<Trie>][];
3625
child(id: number): Promise<Trie>?;
3726
}
@@ -41,6 +30,8 @@ declare namespace stringdex {
4130
interface DataColumn {
4231
isEmpty(id: number): boolean;
4332
at(id: number): Promise<Uint8Array|undefined>;
33+
search(name: Uint8Array|string): Promise<Trie?>;
34+
searchLev(name: Uint8Array|string): AsyncGenerator<Trie>;
4435
length: number,
4536
}
4637
/**

0 commit comments

Comments
 (0)