Skip to content

Conversation

asimarslan
Copy link
Contributor

performance improvement on serialization bits, codecs and lazyDictioary introduced

@devOpsHazelcast
Copy link
Contributor

Windows .Net Framework Tests FAILed.

@devOpsHazelcast
Copy link
Contributor

Linux Net Core Tests FAILed.

@devOpsHazelcast
Copy link
Contributor

Windows Net Core Tests FAILed.

@asimarslan
Copy link
Contributor Author

verify

@asimarslan asimarslan added this to the 3.12 milestone May 3, 2019
@devOpsHazelcast
Copy link
Contributor

Windows .Net Framework Tests FAILed.

@asimarslan asimarslan force-pushed the feature/performance-improvements branch from 036c96f to f91f491 Compare May 3, 2019 08:53
@devOpsHazelcast
Copy link
Contributor

Linux Net Core Tests FAILed.

@devOpsHazelcast
Copy link
Contributor

Windows Net Core Tests FAILed.

@asimarslan asimarslan requested review from ihsandemir and sancar May 3, 2019 08:57
@asimarslan asimarslan changed the title [WIP]performance improvement Performance improvement May 3, 2019
object value;
if (_nearCache.TryGetValue(keyData, out value))
{
keyList.Remove(keyData);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are iterating over the keyList with indexes and calling remove in the middle. It looks like we will have array index out of bound exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted the iteration

@devOpsHazelcast
Copy link
Contributor

Linux Net Core Tests FAILed.

@devOpsHazelcast
Copy link
Contributor

Windows .Net Framework Tests FAILed.

@devOpsHazelcast
Copy link
Contributor

Windows Net Core Tests FAILed.

}

internal class ResponseParameters
internal static void DecodeResponse(IClientMessage clientMessage, ConcurrentQueue<KeyValuePair<IData, object>> result)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the optimization using a concrete implementation instead of the interface? Can you share the performance numbers how this improves performance?

What about elimination of the class ResponseParameters class with the static method?
I see that only 5 codecs are changed, should this be applied to all the other codecs as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a IMap optimization that we can backport in 4.0 series to all codecs

dataSize += ParameterUtil.CalculateDataSize(name);
dataSize += Bits.IntSizeInBytes;
foreach (var keysItem in keys)
for (int i = 0; i < keys.Count; i++)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this change affect performance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on .Net foreach is slower than for loop

var newCapacity = QuickMath.NextPowerOfTwo(requiredCapacity);
var newBuffer = new byte[newCapacity];
Array.Copy(_protocolBuffer.ByteArray(), 0, newBuffer, 0, _capacity);
Buffer.BlockCopy(_protocolBuffer.ByteArray(), 0, newBuffer, 0, _capacity);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the performance improvement? :
Array.Copy iterates each element while Buffer.BlockCopy performs block of memcpy? So, can we assume that we always need to prefer memcpy to iteration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Buffer.BlockCopy is faster than Array.Copy. both are native calls and I'm not sure of the reason. I can measure improvement.

}

public virtual void PutLong(int index, long value)
public void PutLong(int index, long value)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting. So, virtual methods and interfaces seem to decrease performance for .Net. I am surprised that the .NET virtual machine does not optimize these usages.

Copy link
Contributor Author

@asimarslan asimarslan May 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes virtual methods and interface calls add extra overhead.

public virtual void GetBytes(int index, byte[] dst, int offset, int length)
public void GetBytes(int index, byte[] dst, int offset, int length)
{
BoundsCheck(index, length);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be also unneeded even if previously when Array.Copy was used, since Array.Copy method also does bounds check and throw ArgumentOutOfRangeException when length was not sufficient, right? I wonder how much performance affect this had.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it as it's unnecessary. This is bound check is on all of the hot path so every peny count on this kink of hot paths.

for (var i = 0; i < resultingKeyValuePairs.Count;)
});
base.GetAllInternal(partitionToKeyData, resultingKeyValuePairs);
Parallel.ForEach(resultingKeyValuePairs, kvp =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting optimization. does this speed up when number of entries is over a certain number or is it better to use even if the number of keys is small like say 5 (since I assume there will be a cost of splitting the data to different threads and merging) ?

ExceptionUtil.Rethrow(e);
}
return result;
return new ReadOnlyLazyDictionary<TKey, TValue>(resultingKeyValuePairs, GetContext().GetSerializationService());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a performance number for how much this lazy usage improve the performance in case where the object is always used and deserialized finally event when lazy?

var partitions = new ArrayList(partitionCount);
for (var i = 0; i < partitionCount; i++)
{
partitions.Add(ArrayList.Synchronized(new ArrayList()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need a Synchronized list here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes the next parallel loop will use it but when I benchmark it, I saw itS even faster than concurrentQueue as most of the time is used on the serialization and threads rarely make sync calls.

}
else
{
if (itemData.Equals(serializationService.ToData(dValue)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you benefit if you cache this deserialized object? A second call to Contains will be much faster using the cache, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A second call to Contains is quite a rare case for this list. 99% will just loop over it. But if I cache it, that will be a memory overhead for every case.
Moreover contains method is just implemented just not to leave it empty.

@asimarslan asimarslan force-pushed the feature/performance-improvements branch from f91f491 to a8b605c Compare May 3, 2019 11:52
@devOpsHazelcast
Copy link
Contributor

Linux Net Core Tests FAILed.

@devOpsHazelcast
Copy link
Contributor

Windows .Net Framework Tests FAILed.

@devOpsHazelcast
Copy link
Contributor

Windows Net Core Tests FAILed.

@asimarslan asimarslan force-pushed the feature/performance-improvements branch from a8b605c to 2f45345 Compare May 3, 2019 12:41
@devOpsHazelcast
Copy link
Contributor

Linux Net Core Tests FAILed.

@devOpsHazelcast
Copy link
Contributor

Windows .Net Framework Tests FAILed.

@devOpsHazelcast
Copy link
Contributor

Windows Net Core Tests FAILed.

@asimarslan asimarslan force-pushed the feature/performance-improvements branch from 2f45345 to 1cdb044 Compare May 3, 2019 14:11
@devOpsHazelcast
Copy link
Contributor

Linux Net Core Tests FAILed.

@devOpsHazelcast
Copy link
Contributor

Windows .Net Framework Tests FAILed.

@devOpsHazelcast
Copy link
Contributor

Windows Net Core Tests FAILed.

@asimarslan asimarslan force-pushed the feature/performance-improvements branch from 1cdb044 to 0d4ae8c Compare May 3, 2019 14:58
@devOpsHazelcast
Copy link
Contributor

Linux Net Core Tests FAILed.

@devOpsHazelcast
Copy link
Contributor

Windows .Net Framework Tests FAILed.

@devOpsHazelcast
Copy link
Contributor

Windows Net Core Tests FAILed.

@asimarslan asimarslan force-pushed the feature/performance-improvements branch 2 times, most recently from 0f08169 to b719af2 Compare May 3, 2019 17:30
@devOpsHazelcast
Copy link
Contributor

Windows .Net Framework Tests FAILed.

@devOpsHazelcast
Copy link
Contributor

Windows Net Core Tests FAILed.

@devOpsHazelcast
Copy link
Contributor

Linux Net Core Tests FAILed.

1 similar comment
@devOpsHazelcast
Copy link
Contributor

Linux Net Core Tests FAILed.

@devOpsHazelcast
Copy link
Contributor

Windows Net Core Tests FAILed.

@devOpsHazelcast
Copy link
Contributor

Windows .Net Framework Tests FAILed.

@asimarslan
Copy link
Contributor Author

verify

@devOpsHazelcast
Copy link
Contributor

Linux Net Core Tests FAILed.

@devOpsHazelcast
Copy link
Contributor

Windows Net Core Tests PASSed.

@devOpsHazelcast
Copy link
Contributor

Windows .Net Framework Tests FAILed.

@asimarslan
Copy link
Contributor Author

run-net

@devOpsHazelcast
Copy link
Contributor

Windows .Net Framework Tests FAILed.

@asimarslan asimarslan force-pushed the feature/performance-improvements branch from b719af2 to 052dc34 Compare May 3, 2019 19:19
@devOpsHazelcast
Copy link
Contributor

Linux Net Core Tests PASSed.

@devOpsHazelcast
Copy link
Contributor

Windows .Net Framework Tests PASSed.

@devOpsHazelcast
Copy link
Contributor

Windows Net Core Tests PASSed.

@asimarslan asimarslan merged commit 4c28d90 into hazelcast:master May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants