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

Use abseil maps even more #4473

Merged
merged 11 commits into from
Mar 1, 2024
Merged

Use abseil maps even more #4473

merged 11 commits into from
Mar 1, 2024

Conversation

asl
Copy link
Contributor

@asl asl commented Feb 27, 2024

This is PR on top of #4459 to show how we can improve the things even more with better data structures.

Essentially, this uses more efficient data structures on some hot code paths:

  • abseil hash maps / sets in reference resolver and type map
  • abseil maps / sets & pre-allocated vector in use-def analisys
  • remove some useless allocations and memory traffic in use def

Here are results:

Command Mean [s] Min [s] Max [s] Relative
gtestp4c-abseil --gtest_filter=P4CParserUnroll.switch_20160512 6.056 ± 0.232 5.773 6.465 1.29 ± 0.05
gtestp4c --gtest_filter=P4CParserUnroll.switch_20160512 4.701 ± 0.061 4.600 4.783 1.00

gtestp4c-abseil is #4459 (so yes 78% faster a total compared to main).

@asl
Copy link
Contributor Author

asl commented Feb 27, 2024

I think some other benchmarks are also required. Unfortunately, we do not have much that could be ported from downstream to "stock" p4c.

@asl asl added the run-validation Use this tag to trigger a Validation CI run. label Feb 27, 2024
Copy link
Contributor

@vlstill vlstill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went over the C++ changes. This definitely goes in the right direction, thank you. But I have some points that I believe needs to be addressed. You seem to be using Util::Hash only sometimes, and it is not clear to me if this is deliberate, or if it is an omission. Also, I suggest we make the get availble for the abseil maps to simplify both migration and the code itself.

frontends/common/resolveReferences/referenceMap.cpp Outdated Show resolved Hide resolved
frontends/p4/def_use.h Show resolved Hide resolved
frontends/p4/def_use.h Show resolved Hide resolved
frontends/p4/simplifyDefUse.cpp Outdated Show resolved Hide resolved
frontends/p4/simplifyDefUse.cpp Outdated Show resolved Hide resolved
BUILD.bazel Outdated Show resolved Hide resolved
cmake/Linters.cmake Outdated Show resolved Hide resolved
@fruffy fruffy added the core Topics concerning the core segments of the compiler (frontend, midend, parser) label Feb 28, 2024
@@ -17,9 +17,9 @@ limitations under the License.
#ifndef COMMON_RESOLVEREFERENCES_RESOLVEREFERENCES_H_
#define COMMON_RESOLVEREFERENCES_RESOLVEREFERENCES_H_

#include "absl/container/flat_hash_map.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, can we make absl a bracketed system include to be consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think someone asked somewhere exactly the opposite for fetched dependencies :)

Copy link
Collaborator

@fruffy fruffy Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really? I believe all our fetched dependencies (protobuf, gtest, inja, z3) are included using bracketed includes. Can you point me to the discussion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to find. But I'm happy to change to angled brackets. This makes much more sense to me :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, apparently abseil expects to use quoted includes. And bazel build even enforces this (the path is exported as -iquoted).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, seems to be an opinionated maintainer. This might cause issues with Werror and clang-tidy. Not a big deal but annoying.

We can just patch this, I can get this done in a separate PR.

@asl asl requested a review from fruffy February 29, 2024 03:46
@asl asl force-pushed the map-upd branch 5 times, most recently from 5c38f07 to 83fff4d Compare February 29, 2024 04:54
Copy link
Collaborator

@fruffy fruffy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving from my side.

@asl asl added this pull request to the merge queue Mar 1, 2024
Merged via the queue into p4lang:main with commit 1fba085 Mar 1, 2024
17 checks passed
@asl asl deleted the map-upd branch March 1, 2024 08:22
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) run-validation Use this tag to trigger a Validation CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants