Skip to content

Try to make FieldDef smaller #157003

Description

@panstromek

#156824 added 32 bytes mut_restriction field to FieldDef which increased its size to 136 bytes. This might have caused a small regression in #156881 (comment)

mut_restriction, together with safety and default fields are all unstable features, so assuming they are not used very often, we might be able to get the size and perf back if we extract them out into something like Option<Box<FieldDefExtras>> and keep it None in the default case:

// before
pub struct FieldDef {
    pub attrs: AttrVec,
    pub id: NodeId,
    pub span: Span,
    pub vis: Visibility,
    pub mut_restriction: MutRestriction,
    pub safety: Safety,
    pub ident: Option<Ident>,

    pub ty: Box<Ty>,
    pub default: Option<AnonConst>,
    pub is_placeholder: bool,
}
//after
pub struct FieldDef {
    pub attrs: AttrVec,
    pub id: NodeId,
    pub span: Span,
    pub vis: Visibility,
    pub ident: Option<Ident>,

    pub extras: Option<Box<FieldDefExtras>>,

    pub ty: Box<Ty>,
    pub is_placeholder: bool,
}

pub struct FieldDefExtras {
    pub mut_restriction: MutRestriction,
    pub safety: Safety,
    pub default: Option<AnonConst>,
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-compiletimeIssue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions