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

Replace dominators algorithm with simple Lengauer-Tarjan #85013

Merged
merged 11 commits into from
Dec 7, 2021

Commits on Dec 6, 2021

  1. Implement the simple Lengauer-Tarjan algorithm

    This replaces the previous implementation with the simple variant of
    Lengauer-Tarjan, which performs better in the general case. Performance on the
    keccak benchmark is about equivalent between the two, but we don't see
    regressions (and indeed see improvements) on other benchmarks, even on a
    partially optimized implementation.
    
    The implementation here follows that of the pseudocode in "Linear-Time
    Algorithms for Dominators and Related Problems" thesis by Loukas Georgiadis. The
    next few commits will optimize the implementation as suggested in the thesis.
    Several related works are cited in the comments within the implementation, as
    well.
    
    Implement the simple Lengauer-Tarjan algorithm
    
    This replaces the previous implementation (from rust-lang#34169), which has not been
    optimized since, with the simple variant of Lengauer-Tarjan which performs
    better in the general case. A previous attempt -- not kept in commit history --
    attempted a replacement with a bitset-based implementation, but this led to
    regressions on perf.rust-lang.org benchmarks and equivalent wins for the keccak
    benchmark, so was rejected.
    
    The implementation here follows that of the pseudocode in "Linear-Time
    Algorithms for Dominators and Related Problems" thesis by Loukas Georgiadis. The
    next few commits will optimize the implementation as suggested in the thesis.
    Several related works are cited in the comments within the implementation, as
    well.
    
    On the keccak benchmark, we were previously spending 15% of our cycles computing
    the NCA / intersect function; this function is quite expensive, especially on
    modern CPUs, as it chases pointers on every iteration in a tight loop. With this
    commit, we spend ~0.05% of our time in dominator computation.
    Mark-Simulacrum committed Dec 6, 2021
    Configuration menu
    Copy the full SHA
    e8d7248 View commit details
    Browse the repository at this point in the history
  2. Optimization: Merge parent and ancestor arrays

    As the paper indicates, the unprocessed vertices in the DFS tree and processed
    vertices are disjoint, and we can use them in the same space, tracking only the index
    of the split.
    Mark-Simulacrum committed Dec 6, 2021
    Configuration menu
    Copy the full SHA
    c82fe0e View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    7379d24 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    92186cb View commit details
    Browse the repository at this point in the history
  5. Use preorder indices for data structures

    This largely avoids remapping from and to the 'real' indices, with the exception
    of predecessor lookup and the final merge back, and is conceptually better.
    Mark-Simulacrum committed Dec 6, 2021
    Configuration menu
    Copy the full SHA
    7d12767 View commit details
    Browse the repository at this point in the history
  6. Remove separate RPO traversal

    This integrates the preorder and postorder traversals into one.
    Mark-Simulacrum committed Dec 6, 2021
    Configuration menu
    Copy the full SHA
    8991002 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    345ada0 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    cc63ec3 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    2b63059 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    3187480 View commit details
    Browse the repository at this point in the history

Commits on Dec 7, 2021

  1. Configuration menu
    Copy the full SHA
    15483cc View commit details
    Browse the repository at this point in the history