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 IR::Annotations and make IAnnotated to carry annotations inline #4992

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

asl
Copy link
Contributor

@asl asl commented Nov 1, 2024

Lots of cleanups and fixes here and there

@asl asl added core Topics concerning the core segments of the compiler (frontend, midend, parser) run-validation Use this tag to trigger a Validation CI run. run-sanitizer Use this tag to run a Clang+Sanitzers CI run. breaking-change This change may break assumptions of compiler back ends. labels Nov 1, 2024
@asl
Copy link
Contributor Author

asl commented Nov 1, 2024

This is PR on top of #4971 for simplicity.

As mentioned in #4974, IR::Annotations incur a huge overhead, and in general does not make any sense: it's just another level of indirection. So, this just implements old FIXME, plus does some cleanup here and there.

The impact of # of allocations is huge.
Before:
image
After:
Screenshot 2024-11-01 at 15 49 14

So, we're 10% less of memory allocations by both total size and number.

The runtime impact with GC disabled is huge as well:

Command Mean [s] Min [s] Max [s] Relative
test/gtestp4c-nogc-main --gtest_filter=P4CParserUnroll.switch_20160512 3.240 ± 0.048 3.195 3.422 1.10 ± 0.03
test/gtestp4c-nogc --gtest_filter=P4CParserUnroll.switch_20160512 2.948 ± 0.061 2.855 3.041 1.00

So, we're 10% faster here (!)

Runtime impact with GC on is much less visible due to huge GC overhead (1.5x):

Command Mean [s] Min [s] Max [s] Relative
test/gtestp4c-main --gtest_filter=P4CParserUnroll.switch_20160512 4.584 ± 0.099 4.312 4.897 1.02 ± 0.03
test/gtestp4c --gtest_filter=P4CParserUnroll.switch_20160512 4.512 ± 0.072 4.309 4.649 1.00

@asl
Copy link
Contributor Author

asl commented Nov 1, 2024

sanitizers are broken after #4989

@@ -154,7 +157,7 @@ class P4Control : Type_Declaration, INestedNamespace, ISimpleNamespace, IApply,

/// A P4-16 action
class P4Action : Declaration, ISimpleNamespace, IAnnotated, IFunctional {
optional Annotations annotations = Annotations::empty;
Copy link
Contributor

@ChrisDodd ChrisDodd Nov 6, 2024

Choose a reason for hiding this comment

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

Would we get most/all of the memory savings by just using inline here instead of getting rid of IR::Annotations completely? That might be a simpler change.

Copy link
Contributor Author

@asl asl Nov 6, 2024

Choose a reason for hiding this comment

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

Not all, as IR::Annotations will be still be a Node and it will still be cloned. Though "invisible" now when outer node is cloned by itself. Plus, there was already a FIXME for this change. I think additional wrapper is not required as annotation is a property of the Node itself, so why do we need to have additional level of indirection? For convenience we can certainly do using Annotations = IR::Vector<IR::Annotation> here, yes.

Plus I already fixed couple of bugs when it was Annotations (being a Node) queried for the presence of an Annotation. Certainly the check returned always false. Now only IAnnotated objects could be queried about annotations.

In addition to this: usually we only have 1-2 annotations max (e.g. @name and that's it). So we can store them inline using e.g. absl::InlineVector as underlying storage. This would remove almost all Annotation-related memory allocations. But first we'd need to reduce the size of Allocation itself IMO

Signed-off-by: Anton Korobeynikov <[email protected]>
initializer_list while there

Signed-off-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
Lots of cleanups and fixes here and there

Signed-off-by: Anton Korobeynikov <[email protected]>
@asl
Copy link
Contributor Author

asl commented Nov 6, 2024

I rebased the branch after abseil string helpers were merged in. Now it should show the changes more cleanly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change This change may break assumptions of compiler back ends. core Topics concerning the core segments of the compiler (frontend, midend, parser) run-sanitizer Use this tag to run a Clang+Sanitzers CI run. run-validation Use this tag to trigger a Validation CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants