Liran Zelkha has uploaded a new change for review. Change subject: core: Cache GUID creation ......................................................................
core: Cache GUID creation Since UUID.fromString is cpu consuming, and occurs many times in the course of regular system operation, we are caching the UUID creation. Note that this code runs both on server and in GWT. Change-Id: I49a103f6194d9c4b703c1bc965b5a56bba4e9634 Signed-off-by: [email protected] <[email protected]> --- M backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/NGuid.java 1 file changed, 21 insertions(+), 4 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/79/16079/1 diff --git a/backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/NGuid.java b/backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/NGuid.java index f4e8d46..2775efb 100644 --- a/backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/NGuid.java +++ b/backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/NGuid.java @@ -1,11 +1,15 @@ package org.ovirt.engine.core.compat; import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; public class NGuid implements Serializable, Comparable<NGuid> { protected static final String EMPTY_GUID_VALUE = "00000000-0000-0000-0000-000000000000"; + + protected static final UUID EMPTY_GUID = UUID.fromString(EMPTY_GUID_VALUE); /** * Needed for the serialization/deserialization mechanism. @@ -17,6 +21,8 @@ private static final byte[] KEEP_BYTE_ORDER_INDICES = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; + private Map<String, UUID> cachedGuids = new HashMap<String, UUID>(); + public final static Guid Empty = new Guid(); public static Guid NewGuid() { @@ -38,10 +44,21 @@ public NGuid(byte[] guid, boolean keepByteOrder) { String guidAsStr = getStrRepresentationOfGuid(guid, keepByteOrder); if (guidAsStr.isEmpty()) { - uuid = UUID.fromString(EMPTY_GUID_VALUE); + uuid = EMPTY_GUID; } else { - uuid = UUID.fromString(guidAsStr); + uuid = createGuidOrGetFromCache(guidAsStr); } + } + + private UUID createGuidOrGetFromCache(String guidAsStr) { + UUID cachedGuid = cachedGuids.get(guidAsStr); + + if (cachedGuid == null) { + cachedGuid = UUID.fromString(guidAsStr); + cachedGuids.put(guidAsStr, cachedGuid); + } + + return cachedGuid; } public NGuid(String candidate) { @@ -50,9 +67,9 @@ "candidate can not be null please use static method createGuidFromString"); } if (candidate.isEmpty()) { - uuid = UUID.fromString(EMPTY_GUID_VALUE); + uuid = EMPTY_GUID; } else { - uuid = UUID.fromString(candidate); + uuid = createGuidOrGetFromCache(candidate); } } -- To view, visit http://gerrit.ovirt.org/16079 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I49a103f6194d9c4b703c1bc965b5a56bba4e9634 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Liran Zelkha <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
