Open
Description
This is a special case of #76382. Attributes
is 72 bytes large and used in quite a few places:
This has two downsides:
- Attributes takes up a lot of space in memory, so this bloats memory usage
- It means attributes have to calculated ahead of time, instead of on-demand. In particular, this requires adding a new attrs field whenever
render
needs to look at the attrs of a specificclean
type (Add stability tags to ImportItem. #83900 (comment)).
It would be better to calculate this on-demand, so it uses less memory and doesn't have to be calculated for each and every item.
Metadata
Metadata
Assignees
Labels
Category: PRs that clean code up or issues documenting cleanup.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Issue: Problems and improvements with respect to memory usage during compilation.Relevant to the rustdoc team, which will review and decide on the PR/issue.
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
jyn514 commentedon Apr 18, 2021
Steps to implement this:
Attributes
to functions onAttributesExt
.from_ast
, so you'll have to pass in some context. I wonder if reporting a diagnostic there is actually necessary - I'd expect rustc to verify thatdoc(cfg)
has valid syntax, if it doesn't already, we could move it intocheck_doc_attrs
:rust/compiler/rustc_passes/src/check_attr.rs
Line 596 in b0c818c
additional_attrs
- this is used for inlining:rust/src/librustdoc/clean/inline.rs
Line 300 in b021bee
inlined_attrs
field onCache
- that would let render calculate all this on-demand without having to come up with some crazy scheme to update the attrs in the main TyCtxt. Hopefully a simpleHashMap<DefId, (Attributes, /*parent_module: */ DefId)>
mapping will be enough; I don't know if we ever need to deal with attributes for something without a DefId.Attributes
to functions on AttributesExt; this is the easy part.tdelabro commentedon Apr 19, 2021
So the new
Attributes
fields should bediagnostic
,attrs
andadditional_attrs
, aka the arguements required by a call tofrom_ast
?jyn514 commentedon Apr 19, 2021
There should be no
diagnostic
at all - I have a suspicion it's not doing anything currently, but in case it is, those checks should be moved out of rustdoc and into rustc.Hmm, keeping
Attributes
but only storingattrs
andadditional_attrs
is an interesting idea. I would be ok with that too - my original plan was to get rid of Attributes altogether, but that would be harder than holding on to additional_attrs.tdelabro commentedon Apr 19, 2021
@rustbot claim
tdelabro commentedon Apr 19, 2021
I will give it a try. I'm not familiar with the codebase but keeping a lightened
Attributes
and compute its fields on the fly doesn't seem to hard of a refacto.I will message you on Zulip if I have any questions.