[google-appengine] Performance Implications on using "Key as Encoded String"

78 views
Skip to first unread message

luka

unread,
May 15, 2010, 12:55:15 PM5/15/10
to Google App Engine
Hey,

I am currently using "Key as Encoded String" on the child entities of
my application model.
When I create new child entity I set a special unique key to it using:

java.util.UUID.randomUUID()

This method ensure key uniqueness although it create a 144 character
long string, which I fear will damage performance (due to his length),
is my suspicious right ? should I employ other means to create unique
key ?

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.

François Masurel

unread,
May 15, 2010, 6:11:29 PM5/15/10
to Google App Engine
I'm using this code to compact my UUIDs down to 22 chars strings :

public static String asBase64String(UUID uuid) {
return Base64.encodeBase64String(asByteArray(uuid));
}

public static byte[] asByteArray(UUID uuid) {

long msb = uuid.getMostSignificantBits();
long lsb = uuid.getLeastSignificantBits();

byte[] buffer = new byte[16];

for (int i = 0; i < 8; i++) {
buffer[i] = (byte) (msb >>> 8 * (7 - i));
}
for (int i = 8; i < 16; i++) {
buffer[i] = (byte) (lsb >>> 8 * (7 - i));
}

return buffer;

}

I'm using Apache Commons Codec for Base64 computations but other
librairies are available.
Reply all
Reply to author
Forward
0 new messages