From b25fcb4de1e12a447fbe6ac0a6290c78f88a4426 Mon Sep 17 00:00:00 2001 From: Jian Li Date: Fri, 12 May 2017 02:12:49 +0900 Subject: [PATCH] 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 --- .../org/onosproject/lisp/msg/protocols/LispEidRecord.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/LispEidRecord.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/LispEidRecord.java index 41d758368a..5a8fd6cb36 100644 --- a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/LispEidRecord.java +++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/LispEidRecord.java @@ -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; } /**