Improve MapDB read performance by using cached hash code

With existing implementation, the hashcode of LispEidRecord
should always be recaluclated when we lookup MapDB.
If we have very large number of entries stored in a HashMap,
the performance becomes very poor.
With this cached hashcode implementation, we can improve
the MapDB lookup performance.

Change-Id: Ie193e0b96b2bdc470e52f6f1de4f341527e0507d
This commit is contained in:
Jian Li 2017-05-12 02:12:49 +09:00
parent 24d9be7431
commit b25fcb4de1

View File

@ -35,6 +35,9 @@ public final class LispEidRecord {
private final byte maskLength;
private final LispAfiAddress prefix;
// Cache the hash code for the string, default to 0
private final int hash;
/**
* Initializes LispEidRecord with mask length and EID prefix.
*
@ -47,6 +50,7 @@ public final class LispEidRecord {
checkNotNull(prefix, "Must specify an address prefix");
this.prefix = prefix;
this.hash = 31 * 17 + Objects.hashCode(maskLength, prefix);
}
/**
@ -90,7 +94,7 @@ public final class LispEidRecord {
@Override
public int hashCode() {
return Objects.hashCode(maskLength, prefix);
return hash;
}
/**