Skip to content

Optimize strnom::whitespace #126

Closed
Closed
@dtolnay

Description

@dtolnay

I wrote a benchmark that uses Syn to parse everything in the rust-lang/rust repo + submodules and it spends more than 10% of its time in this function. It would be good to optimize as much as possible if anyone is interested -- but without increasing compile time of proc-macro2.

Here is a minimal benchmark to reproduce and optimize:

// [dependencies]
// proc-macro2 = { version = "0.4", default-features = false }

fn main() {
    let path = "../rust/src/libsyntax/parse/parser.rs";
    let content = std::fs::read_to_string(path).unwrap();
    for _ in 0..1000 {
        content.parse::<proc_macro2::TokenStream>().unwrap();
    }
}
$ cargo build --release
$ valgrind --tool=callgrind target/release/bench-procmacro2
$ callgrind_annotate --auto=yes callgrind.out.*

In this program 41% of instructions executed are associated with strnom::whitespace.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions