-
Notifications
You must be signed in to change notification settings - Fork 13.4k
rustdoc-json-types
: Intern Type
s to deduplicate and flatten
#142327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
rustdoc-json-types
: Intern Type
s to deduplicate and flatten
#142327
Conversation
rustbot has assigned @aDotInTheVoid. Use |
rustdoc-json-types is a public (although nightly-only) API. If possible, consider changing cc @CraftSpider, @aDotInTheVoid, @Enselic, @obi1kenobi This PR modifies cc @jieyouxu These commits modify Please ensure that if you've changed the output:
|
This comment has been minimized.
This comment has been minimized.
Apparently rustdoc_json is the hot new optimization target: I just filed #142335. That PR doesn't touch rustdoc-json-types, however; its changes are all on the rustdoc side. There will be some conflicts between that PR and this PR (especially in |
rustdoc-types
deBox
ificationrustdoc-json-types
: Intern Types
to deduplicate and flatten
rustdoc-json-types
: Intern Types
to deduplicate and flattenrustdoc-json-types
: Intern Type
s to deduplicate and flatten
The overall approach of interning
Yeah, this PR's current approach is fragile to any change to the order types are inserted to the If we could do something like Also, some advice: This would be alot easier to review if it was split into logically separate commits (i.e. all the tests still pass after each commit). In paticular, if the |
According to the JSONPath spec, there's no way to achieve dynamic indexing. We can try to implement some kind of extension like it's done in |
Based on the comments from when it was first added (#81063), it was because we used XPath for the HTML tests, and JSONPath was a similar thing to that but for json. I'd not be opposed to moving rustdoc-json tests to jq, especially given that it seems to natively support having variables. |
☔ The latest upstream changes (presumably #142358) made this pull request unmergeable. Please resolve the merge conflicts. |
I can confirm that the choice of JSONPath was largely unprincipled - |
Ok, I'll try to tackle the infra. @aDotInTheVoid, could you please provide up-to-date info about what needs to be done besides fixing the JSONPath constraints? I've found #94140, but it seems to be outdated in some parts. I think you can try to update it and assign me to it. |
The current format of
rustdoc-types
has a problem that potentially prevents it from being parsed by the majority of JSON parsers, includingserde_json
. Generally, they're implemented via recursion meaning that they'll hit their depth limit or invoke a stack overflow if a JSON blob has too deeply nested data. This creates issues like obi1kenobi/cargo-semver-checks#108. I don't think that the problem has anything to do with parsers' limitations. Instead, I consider it as a format design flaw.rustdoc-types
implementsType
as a recursive structure by usingBox
es. I've removed them and added thetypes
field toCrate
that can be indexed akin toCrate::index
. This eliminated the recursive property ofType
makingrustdoc-types
parseable with much more deeply nested crates likediesel
.I've also added a test that demonstrates that
rustdoc-types
doesn't grow in depth anymore. Thanks to @weiznich for this snippet.The only known to me problem with these changes is that the current testing approach for
rustdoc-types
ostensibly makes everything to stop you from using indexes from the same JSON blob it's querying. I've fixed all broken tests by just hardcoding type identifiers, though something tells me this isn't really deterministic, but I have no idea about other options, so I'll really appreciate any help here.As for other improvements, due to hashing of types at the render stage, there are no more duplicated types in a resulted JSON blob, i.e. resulted JSON blobs are much smaller now. I've done a test with
diesel
by generating 2 JSON blobs withcargo rustdoc -Zunstable-options --lib --output-format=json -F extras,128-column-tables -p diesel -- --document-private-items
.rustdoc
1.87 generated 231 MB, the PR'srustdoc
generated 76 MB (3x smaller). This should drastically improve the speed of tools that userustdoc-types
.