Skip to content

Investigating compressing fallback spans into fewer bytes #167

@dtolnay

Description

@dtolnay

The compiler's proc_macro::Span uses an efficient encoding in 4 bytes. Currently our span when procmacro2_semver_exempt is enabled is a whopping 12 bytes because it essentially looks like:

enum Span { // tag + padding = 4 bytes
    Compiler(proc_macro::Span), // 4 bytes
    Fallback(struct Span { // 8 bytes
        lo: u32,
        hi: u32,
    }),
}

And it goes up to 16 bytes when embedded next to 8-byte pointers due to additional padding.

This has a performance impact because syntax trees contain lots of spans.

We need to investigate interning the spans or some other trick to cut the size.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions