Skip to content

Commit 05ea1b9

Browse files
Rollup merge of rust-lang#153283 - LukeMathWalker:add-rkyv-support, r=aDotInTheVoid
feat(rustdoc-json): Add optional support for rkyv (de)serialization ## Motivation The JSON documents produced by `rustdoc-json` are _big_. More often than not, tools need to access a small fraction of that output—e.g. a couple of types from a transitive dependency, or a subset of the fields on a given `rustdoc-json-types` type. Using a binary (de)serialization format and a cache helps to drive down the performance cost of deserialization: you invoke `rustdoc-json` to get the JSON output you need, re-serialize it using a more perfomant format as target (e.g. `bincode` or `postcard`) and thus amortize the cost of future queries that hit the persistent cache rather than `rustdoc-json`. This is _better_, but still not great: the deserialization cost for crates like `std` still shows up prominently in flamegraphs. ## An Alternative Approach: rkyv `rkyv` provides a different opportunity: you avoid paying the deserialization cost _upfront_ thanks to [zero-copy deserialization](https://rkyv.org/zero-copy-deserialization.html). You're often able to determine if you need a certain entry from the JSON document using the archived version of that type, thus incurring the full deserialization cost only for the subset of items you actually need ([example](LukeMathWalker/pavex@d067e7e)). ## The Change This PR adds support for `rkyv` behind a feature flag (`rkyv_0_8`). For most types, it's a straight-forward `derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)` annotation. For co-recursive types, we need to adjust the generated bounds, using the techniques from [`rkyv`'s JSON example](https://github.com/rkyv/rkyv/blob/985b0230a0b9cb9fce4a4ee9facb6af148e27c8e/rkyv/examples/json_like_schema.rs). I have added new round-trip tests to ensure `rkyv` works as expected. r? @aDotInTheVoid
2 parents 42326d1 + 1f05c76 commit 05ea1b9

5 files changed

Lines changed: 499 additions & 5 deletions

File tree

Cargo.lock

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,41 @@ version = "3.19.0"
376376
source = "registry+https://github.com/rust-lang/crates.io-index"
377377
checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
378378

379+
[[package]]
380+
name = "bytecheck"
381+
version = "0.8.2"
382+
source = "registry+https://github.com/rust-lang/crates.io-index"
383+
checksum = "0caa33a2c0edca0419d15ac723dff03f1956f7978329b1e3b5fdaaaed9d3ca8b"
384+
dependencies = [
385+
"bytecheck_derive",
386+
"ptr_meta",
387+
"rancor",
388+
"simdutf8",
389+
]
390+
391+
[[package]]
392+
name = "bytecheck_derive"
393+
version = "0.8.2"
394+
source = "registry+https://github.com/rust-lang/crates.io-index"
395+
checksum = "89385e82b5d1821d2219e0b095efa2cc1f246cbf99080f3be46a1a85c0d392d9"
396+
dependencies = [
397+
"proc-macro2",
398+
"quote",
399+
"syn 2.0.110",
400+
]
401+
379402
[[package]]
380403
name = "bytecount"
381404
version = "0.6.9"
382405
source = "registry+https://github.com/rust-lang/crates.io-index"
383406
checksum = "175812e0be2bccb6abe50bb8d566126198344f707e304f45c648fd8f2cc0365e"
384407

408+
[[package]]
409+
name = "bytes"
410+
version = "1.11.1"
411+
source = "registry+https://github.com/rust-lang/crates.io-index"
412+
checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
413+
385414
[[package]]
386415
name = "camino"
387416
version = "1.2.1"
@@ -2476,6 +2505,26 @@ dependencies = [
24762505
name = "miropt-test-tools"
24772506
version = "0.1.0"
24782507

2508+
[[package]]
2509+
name = "munge"
2510+
version = "0.4.7"
2511+
source = "registry+https://github.com/rust-lang/crates.io-index"
2512+
checksum = "5e17401f259eba956ca16491461b6e8f72913a0a114e39736ce404410f915a0c"
2513+
dependencies = [
2514+
"munge_macro",
2515+
]
2516+
2517+
[[package]]
2518+
name = "munge_macro"
2519+
version = "0.4.7"
2520+
source = "registry+https://github.com/rust-lang/crates.io-index"
2521+
checksum = "4568f25ccbd45ab5d5603dc34318c1ec56b117531781260002151b8530a9f931"
2522+
dependencies = [
2523+
"proc-macro2",
2524+
"quote",
2525+
"syn 2.0.110",
2526+
]
2527+
24792528
[[package]]
24802529
name = "new_debug_unreachable"
24812530
version = "1.0.6"
@@ -3047,6 +3096,26 @@ dependencies = [
30473096
"cc",
30483097
]
30493098

3099+
[[package]]
3100+
name = "ptr_meta"
3101+
version = "0.3.1"
3102+
source = "registry+https://github.com/rust-lang/crates.io-index"
3103+
checksum = "0b9a0cf95a1196af61d4f1cbdab967179516d9a4a4312af1f31948f8f6224a79"
3104+
dependencies = [
3105+
"ptr_meta_derive",
3106+
]
3107+
3108+
[[package]]
3109+
name = "ptr_meta_derive"
3110+
version = "0.3.1"
3111+
source = "registry+https://github.com/rust-lang/crates.io-index"
3112+
checksum = "7347867d0a7e1208d93b46767be83e2b8f978c3dad35f775ac8d8847551d6fe1"
3113+
dependencies = [
3114+
"proc-macro2",
3115+
"quote",
3116+
"syn 2.0.110",
3117+
]
3118+
30503119
[[package]]
30513120
name = "pulldown-cmark"
30523121
version = "0.11.3"
@@ -3092,6 +3161,15 @@ version = "5.3.0"
30923161
source = "registry+https://github.com/rust-lang/crates.io-index"
30933162
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
30943163

3164+
[[package]]
3165+
name = "rancor"
3166+
version = "0.1.1"
3167+
source = "registry+https://github.com/rust-lang/crates.io-index"
3168+
checksum = "a063ea72381527c2a0561da9c80000ef822bdd7c3241b1cc1b12100e3df081ee"
3169+
dependencies = [
3170+
"ptr_meta",
3171+
]
3172+
30953173
[[package]]
30963174
name = "rand"
30973175
version = "0.8.5"
@@ -3275,6 +3353,15 @@ dependencies = [
32753353
name = "remote-test-server"
32763354
version = "0.1.0"
32773355

3356+
[[package]]
3357+
name = "rend"
3358+
version = "0.5.3"
3359+
source = "registry+https://github.com/rust-lang/crates.io-index"
3360+
checksum = "cadadef317c2f20755a64d7fdc48f9e7178ee6b0e1f7fce33fa60f1d68a276e6"
3361+
dependencies = [
3362+
"bytecheck",
3363+
]
3364+
32783365
[[package]]
32793366
name = "replace-version-placeholder"
32803367
version = "0.1.0"
@@ -3283,6 +3370,36 @@ dependencies = [
32833370
"walkdir",
32843371
]
32853372

3373+
[[package]]
3374+
name = "rkyv"
3375+
version = "0.8.15"
3376+
source = "registry+https://github.com/rust-lang/crates.io-index"
3377+
checksum = "1a30e631b7f4a03dee9056b8ef6982e8ba371dd5bedb74d3ec86df4499132c70"
3378+
dependencies = [
3379+
"bytecheck",
3380+
"bytes",
3381+
"hashbrown 0.16.1",
3382+
"indexmap",
3383+
"munge",
3384+
"ptr_meta",
3385+
"rancor",
3386+
"rend",
3387+
"rkyv_derive",
3388+
"tinyvec",
3389+
"uuid",
3390+
]
3391+
3392+
[[package]]
3393+
name = "rkyv_derive"
3394+
version = "0.8.15"
3395+
source = "registry+https://github.com/rust-lang/crates.io-index"
3396+
checksum = "8100bb34c0a1d0f907143db3149e6b4eea3c33b9ee8b189720168e818303986f"
3397+
dependencies = [
3398+
"proc-macro2",
3399+
"quote",
3400+
"syn 2.0.110",
3401+
]
3402+
32863403
[[package]]
32873404
name = "run_make_support"
32883405
version = "0.0.0"
@@ -4790,6 +4907,7 @@ name = "rustdoc-json-types"
47904907
version = "0.1.0"
47914908
dependencies = [
47924909
"bincode",
4910+
"rkyv",
47934911
"rustc-hash 2.1.1",
47944912
"serde",
47954913
"serde_derive",
@@ -5128,6 +5246,12 @@ version = "0.3.7"
51285246
source = "registry+https://github.com/rust-lang/crates.io-index"
51295247
checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
51305248

5249+
[[package]]
5250+
name = "simdutf8"
5251+
version = "0.1.5"
5252+
source = "registry+https://github.com/rust-lang/crates.io-index"
5253+
checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e"
5254+
51315255
[[package]]
51325256
name = "similar"
51335257
version = "2.7.0"

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3315,7 +3315,7 @@ impl Step for CrateRustdocJsonTypes {
33153315
builder.kind,
33163316
"src/rustdoc-json-types",
33173317
SourceType::InTree,
3318-
&[],
3318+
&["rkyv_0_8".to_owned()],
33193319
);
33203320

33213321
// FIXME: this looks very wrong, libtest doesn't accept `-C` arguments and the quotes are fishy.

src/rustdoc-json-types/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ path = "lib.rs"
88

99
[features]
1010
default = ["rustc-hash"]
11+
rkyv_0_8 = ["dep:rkyv"]
1112

1213
[dependencies]
1314
serde = "1.0"
1415
serde_derive = "1.0"
1516
rustc-hash = { version = "2.0", optional = true }
17+
rkyv = { version = "0.8", optional = true }
1618

1719
[dev-dependencies]
1820
serde_json = "1.0"

0 commit comments

Comments
 (0)