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

Remove multimap usage from memoizeDeclsByName #4821

Merged
merged 2 commits into from
Jul 24, 2024
Merged

Conversation

asl
Copy link
Contributor

@asl asl commented Jul 20, 2024

Use used std::unordered_multimap to store declarations within a namespace having the same name. It turned out it was a bit of overkill:

  • In the vast majority of cases namespace only has unique declarations
  • There was no multimap in Abseil, so we were unable to use these more efficient maps
  • Profiling shows some elevated malloc traffic around these multimaps in downstream applications

This PR switches to:

  • Abseil flat_hash_map to store declarations given name
  • Use inlined vector to store up to 2 declarations inline within a map (so no additional memory allocation is required in the vast majority of cases)

Few improvements along the way. No functionality change

asl added 2 commits July 19, 2024 16:41
This way we can wrap over std::vector<T*> iterator

Signed-off-by: Anton Korobeynikov <anton@korobeynikov.info>
Signed-off-by: Anton Korobeynikov <anton@korobeynikov.info>
@asl asl requested review from vlstill and fruffy July 20, 2024 00:20
@asl
Copy link
Contributor Author

asl commented Jul 20, 2024

Impact on one downstream application:

Command Mean [s] Min [s] Max [s] Relative
baseline 61.816 ± 0.596 61.160 64.674 1.02 ± 0.01
this PR 61.388 ± 0.950 60.019 62.715 1.00

yielding small (2%) but observable speedup.

@fruffy fruffy added the core Topics concerning the core segments of the compiler (frontend, midend, parser) label Jul 21, 2024
@asl asl added this pull request to the merge queue Jul 24, 2024
Merged via the queue into p4lang:main with commit c0bbf1b Jul 24, 2024
17 checks passed
@asl asl deleted the no-multimap branch July 24, 2024 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Topics concerning the core segments of the compiler (frontend, midend, parser)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants