About performance for different Key type


I have a RepositoryBase<TId, TItem> class that can store the TItem type. It know the type of the instance identifier, it is TId.

I create a method to generate the Key to be used to store the Bin in Aerospike.

The problem is about performance. Without any logic I can just use Value. If I apply some logic I can generate the Key basing on the type of TId.

For example if TId is a string or a long I can pass it as it is. If TId is a Guid I have to use .ToString().

That is the code now:

protected abstract Value GetKey(TId id);
// todo: check if using specialized class increase performance
//protected abstract string GetKey(TId key);
//protected abstract long GetPK(TId key);

It is abstract and must be implemented in the inherited class.
I used Value to be most usable as possible.
Real case are often with string ID like “123456.AAA.bbb.{GUID}.something here.{GUID}”, so probably string is the best solution.

My question is: can I have a little performance improvement using string or long instead of Value ?

Any other advice from performances aspect on this point?



All key types will ultimately result in the creation of a Value instance. Performance should be approximately the same since the Value instance is either created explicitly or implicitly through native type key constructors like:

	public Key(string ns, string setName, string key)
		this.ns = ns;
		this.setName = setName;
		this.userKey = new Value.StringValue(key);
		digest = ComputeDigest(setName, this.userKey);

Perfect, thank you.