Skip to content

🛠 improve canonicalization by using a hashing scheme #48417

Closed

Description

@nikomatsakis

The canonicalization scheme created in #48411 works by first folding types into a canonical form, which is then hashed and interned. This is not necessary, and it shows up in the profiles: we could augment the TypeFolder trait to have a method for hashing as it goes (e.g., a hash_with method, and some hash_ty / hash_region callbacks). Then we can begin by hashing the value-to-be-canonicalized, producing a hash (this would be a kind of "stable hash", hence big enough to be presumed unique). We would then look for an interned value with that hash and return it if found, avoiding all the folding. If no interned value is found, then we would fold and put the resulting value into the interning table. Ideally, this hash can then be kept for later, making the "stable hash" code quite cheap.

(This might actually not make things faster, of course, we would want to measure.)

Activity

  1. added
    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.
    on Feb 22, 2018
  2. changed the title [-]improve canonicalization by using a hashing scheme[/-] [+]🛠 improve canonicalization by using a hashing scheme[/+] on Feb 25, 2018
  3. nikomatsakis commented on Feb 25, 2018

    @nikomatsakis
    ContributorAuthor

    That said, in all profiles I've looked at, canonicalization doesn't seem to be a hot spot.

  4. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    on Apr 23, 2018
  5. JaimeValdemoros commented on May 29, 2018

    @JaimeValdemoros

    Hi @nikomatsakis! I'm keen to have a look at this if you don't mind giving me a couple of hints along the way? I have some rust experience but this would be my first time contributing to the compiler.

  6. JaimeValdemoros commented on May 29, 2018

    @JaimeValdemoros

    I had an initial go a adding the hash_with method in a branch here: https://github.com/JaimeValdemoros/rust/tree/pre-canonicalization-hashing

  7. technicalguy commented on Jun 23, 2018

    @technicalguy
    Contributor

    @JaimeValdemoros Are you still working on this? If you make a pull request (even if it's not "finished" or "ready") then it will be much easier for everyone to see your code (rather than getting GitHub to diff your branch against rust/master directly).

  8. nikomatsakis commented on Jun 26, 2018

    @nikomatsakis
    ContributorAuthor

    I'm tagging this with WG-compiler-nll and NLL-performant since this is also an important issue for non-lexical lifetimes. canonicalization takes about 5% of NLL time.

  9. JaimeValdemoros commented on Jun 27, 2018

    @JaimeValdemoros

    Sorry about the delay - I'm still keen give this a shot! I've just made a PR here: #51837 following @technicalguy's suggestion.

  10. nikomatsakis commented on Jun 28, 2018

    @nikomatsakis
    ContributorAuthor
  11. nikomatsakis commented on Jun 28, 2018

    @nikomatsakis
    ContributorAuthor

    Current measurements are showing canonicalization as 11% of NLL check, with the latest optimizations, so this is becoming increasingly relevant.

  12. technicalguy commented on Jun 29, 2018

    @technicalguy
    Contributor

    @nikomatsakis I think I have joined Zulip now...yet another chat application!

  13. nikomatsakis commented on Aug 8, 2018

    @nikomatsakis
    ContributorAuthor

    So, this is a big refactoring, and my measurements suggest that while it would help NLL, it would not make a huge difference. I'm going to remove this from the milestone.

  14. removed this from the Rust 2018 RC milestone on Aug 8, 2018
  15. nikomatsakis commented on Aug 8, 2018

    @nikomatsakis
    ContributorAuthor

    Perhaps, in any case, this was a bit much too chew at once, I'm going to see if I can break it down into smaller steps.

  16. pwnorbitals commented on Oct 3, 2020

    @pwnorbitals

    @nikomatsakis is this issue still being worked on ? This sounds like a great refactoring

  17. technicalguy commented on Oct 11, 2020

    @technicalguy
    Contributor

    is this issue still being worked on ?

    I'm not currently working on it, for one, so go ahead if you're interested!

  18. jackh726 commented on Jun 24, 2022

    @jackh726
    Member

    Closing. This seems like a lot of work for maybe not so much gain.

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

    A-trait-systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.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