-
Notifications
You must be signed in to change notification settings - Fork 228
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
HeaderSpace: use immutable structures internally #780
Conversation
ca70799
to
31c6c08
Compare
Most of the memory in the process is taken up by empty TreeSets and the like. If we use Immutable/Empty data structures for these, we'll save a huge amount of RAM.
31c6c08
to
3af3d92
Compare
projects/batfish-common-protocol/src/main/java/org/batfish/datamodel/Interface.java, line 378 at r1 (raw file):
Changed this to Comments from Reviewable |
Review status: 0 of 35 files reviewed at latest revision, 3 unresolved discussions. projects/batfish/src/main/java/org/batfish/representation/juniper/FwFromDestinationPrefixList.java, line 45 at r1 (raw file):
could add a helper getter to projects/batfish/src/main/java/org/batfish/representation/juniper/FwFromFragmentOffset.java, line 28 at r1 (raw file):
this was a projects/batfish/src/main/java/org/batfish/representation/juniper/JuniperConfiguration.java, line 1210 at r1 (raw file):
does this not need the primary prefix? Cisco includes it. Comments from Reviewable |
projects/batfish/src/main/java/org/batfish/representation/juniper/JuniperConfiguration.java, line 1210 at r1 (raw file): Previously, dhalperi (Dan Halperin) wrote…
(maybe it's already there, tho. to be investigated) Comments from Reviewable |
Reviewed 35 of 35 files at r1. projects/batfish-common-protocol/src/main/java/org/batfish/datamodel/Interface.java, line 378 at r1 (raw file): Previously, dhalperi (Dan Halperin) wrote…
Hmm somewhere we might need to remember order of secondary ips/prefixes, but this is fine for now. projects/batfish/src/main/java/org/batfish/representation/aws_vpcs/NetworkAcl.java, line 95 at r1 (raw file):
Can we use projects/batfish/src/main/java/org/batfish/representation/juniper/FwFromDestinationPrefixList.java, line 45 at r1 (raw file): Previously, dhalperi (Dan Halperin) wrote…
As long as it's well-tested, sure. projects/batfish/src/main/java/org/batfish/representation/juniper/FwFromFragmentOffset.java, line 28 at r1 (raw file): Previously, dhalperi (Dan Halperin) wrote…
Actually most of the places you did concatenation would be fine as projects/batfish/src/main/java/org/batfish/representation/juniper/JuniperConfiguration.java, line 1210 at r1 (raw file): Previously, dhalperi (Dan Halperin) wrote…
I think it was already there, unlike Cisco. Comments from Reviewable |
projects/batfish/src/main/java/org/batfish/representation/juniper/JuniperConfiguration.java, line 1210 at r1 (raw file): Previously, arifogel (Ari Fogel) wrote…
Yes, it was already there. Found in Comments from Reviewable |
Review status: 28 of 38 files reviewed at latest revision, 4 unresolved discussions. projects/batfish/src/main/java/org/batfish/representation/aws_vpcs/NetworkAcl.java, line 95 at r1 (raw file): Previously, arifogel (Ari Fogel) wrote…
Done. projects/batfish/src/main/java/org/batfish/representation/juniper/FwFromDestinationPrefixList.java, line 45 at r1 (raw file): Previously, arifogel (Ari Fogel) wrote…
Done. projects/batfish/src/main/java/org/batfish/representation/juniper/FwFromFragmentOffset.java, line 28 at r1 (raw file): Previously, arifogel (Ari Fogel) wrote…
Ack. Comments from Reviewable |
7abcd16
to
6a63b85
Compare
6a63b85
to
ad819a7
Compare
Reviewed 9 of 9 files at r2. projects/batfish/src/main/java/org/batfish/representation/cisco/CiscoConfiguration.java, line 3265 at r2 (raw file):
I think this would be much more efficient without calls to projects/batfish/src/main/java/org/batfish/representation/vyos/VyosConfiguration.java, line 324 at r2 (raw file):
We should avoid using Comments from Reviewable |
Review status: all files reviewed at latest revision, 2 unresolved discussions. projects/batfish/src/main/java/org/batfish/representation/cisco/CiscoConfiguration.java, line 3265 at r2 (raw file): Previously, arifogel (Ari Fogel) wrote…
Done. projects/batfish/src/main/java/org/batfish/representation/vyos/VyosConfiguration.java, line 324 at r2 (raw file): Previously, arifogel (Ari Fogel) wrote…
Done. The function is used in 15 other places, not touched here. Comments from Reviewable |
Reviewed 2 of 2 files at r3. Comments from Reviewable |
It looks we're spending an obscene amount of memory in empty
TreeSet
andArrayList
classes inHeaderSpace
-related classes.There are a few good ways to move forward:
Allow
null
for empty collections. Callers should wrapgetX
with null-checks. When they want to add an item to a set, they have to initialize.Switch to empty/immutable collections internally. These are generally (much) more memory-efficient. Empty collections are in fact singletons Java-wide; and if we use the Guava classes, we'll likely save some copies when structures are copied/used in multiple places.
setX
contract to accept un-sorted sets or even arbitrary collections.getX().add(x)
->setX(...make a new collection containing getX and x)
.addX
forms that are internally equivalent to the above, but callers may have smarter logic (e.g., most of these are in the same function that allocates the interface)I opted to go with the second.
This change is