Skip to content
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

Split symbol interner into static unsynchronized and dynamic synchronized parts #79425

Closed

Commits on Jan 20, 2021

  1. Split Symbol interner into static and dynamic

    This improves performance of Symbol interning in several ways.
    The main motivation of this work is to prepare rustc for
    efficient parallel builds.
    
    The Symbol lookup table (mapping from strings to Symbol numbers)
    is now split into two separate tables: a static table and a
    dynamic table. The static table contains strings that are known
    to rustc, including all keywords and all `sym::foo` symbols.
    The dynamic table contains strings that rustc discovers while
    compiling, such as "my_super_obscure_function_name".
    
    Since the static table is known at compile time (that is, when
    rustc itself is being compiled), this table can be stored
    entirely in static data structures. We use the `phf` crate to
    generate this table; `phf` generates perfect hash functions.
    
    This allows rustc to perform Symbol lookups for static symbols
    without any multithreaded synchronization, or accessing any
    dynamic data whatsoever.
    
    I measured the percentage of static symbol lookups in many
    common Rust crates, including rust/compiler, rust/library,
    servo, rand, quote, syn, rust-analyzer, rayon, and rsvg.
    Among these crates, between 35% and 55% of all symbol lookups
    were resolved using the static lookup table.
    Arlie Davis committed Jan 20, 2021
    Configuration menu
    Copy the full SHA
    6fa8898 View commit details
    Browse the repository at this point in the history