-
Notifications
You must be signed in to change notification settings - Fork 446
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
Conversation
This is PR on top of #4971 for simplicity. As mentioned in #4974, The impact of # of allocations is huge. So, we're 10% less of memory allocations by both total size and number. The runtime impact with GC disabled is huge as well:
So, we're 10% faster here (!) Runtime impact with GC on is much less visible due to huge GC overhead (1.5x):
|
497afd2
to
aed00f8
Compare
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
I agree.
aed00f8
to
4a82acc
Compare
I rebased the branch after abseil string helpers were merged in. Now it should show the changes more cleanly |
4a82acc
to
fa34687
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you. I went over ir
, midend
and most of frontend
changes (except mainly of P4-14).
bool needsParsing : 1; | ||
|
||
/// If this is true this is a structured annotation, and there are some | ||
/// constraints on its contents. | ||
bool structured : 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the bit-field really decrease size of the struct? Since there are the Vector
/IndexedVector
members, I would expect the alignment to be 64bit and therefore it would not really meatter if the 2 bools are 2 bits or 2 bytes. Or is there another reason to use bit-field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am planning to fix this in subsequent PRs :) We really need a discriminated union here as sizeof(Annotation
) is terrible large. For now I just put it here not to forget.
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
I agree.
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]>
Signed-off-by: Anton Korobeynikov <[email protected]>
692b624
to
78d5ed8
Compare
validate-p4 fixes are in p4gauntlet/toz3#41 |
@smolkaj fyi. This might influence the way you work with annotations. |
@@ -98,7 +98,7 @@ table as { | |||
actions { | |||
a1 | |||
a2 | |||
set_exception | |||
set_exception @defaultonly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually changes the semantics of the program, what change caused this? It looks like this fixes a bug, but would be good to know where this was a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It almost had to have been a change in the DPDK back end code that fixed this, but I haven't tried to narrow down which of those changes it was. The frontend and midend output files have this annotation before and after this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was an obvious bug IMO, see https://github.com/p4lang/p4c/pull/4992/files#diff-2dded02099b0c47be6b37c34d45999cbe59f2ed1e408e6fcc7b73455dff71caaL417
Essentially the checks there were always false as it was IR::Annotations
that was queried, and not the original node.
@asl, apparently this breaks |
@vlstill The debug printing of annotations was pretty broken before this PR. In particular it only prints I'm working on the proper fix when porting |
Lots of cleanups and fixes here and there