sosy-lab / java-common-lib

SoSy-Lab Java Common Library
https://www.sosy-lab.org
Apache License 2.0
12 stars 11 forks source link

Replace PathCopyingPersistentTreeMap hash and size calculation #36

Open Druidos opened 3 years ago

Druidos commented 3 years ago

Replace PathCopyingPersistentTreeMap hash and size calculation from lazy linear algorithm to pre-calculations, which is efficient for public copying methods

PhilippWendler commented 3 years ago

Thanks!

While this certainly increases the performance for some users, it causes higher memory usage for all users of this data structure due to the new fields in the node class. So I would like to understand the effects a little bit better before merging this.

Do you have any numbers on how much improves this performance or how much it increases memory usage in practice? What is your use case that benefits from this? In CPAchecker, for example, we apply hash-code caching for these maps outside of them in those cases where we feel it is relevant, is this possible for you as well?

Druidos commented 3 years ago

If memory consumption is critical, then I will move hash and size calculation from Node into PathCopyingPersistentTreeMap on put/remove-AndCopy. Main idea is to optimize equals(). The hashcode calculation is obtained as a side result of the size calculation. For example, following code twice iterates by whole pMap to identify size change:

boolean compare(PathCopyingPersistentTreeMap<Integer, Integer> pMap) {
    PathCopyingPersistentTreeMap<Integer, Integer> comp = pMap.putAndCopy(1,1);
    return comp.equals(pMap);
}

Exact numbers about performance I can provide later.