Skip to content
This repository has been archived by the owner on Jul 16, 2018. It is now read-only.

Reduce StorageSubscription size #10

Closed
ocoanet opened this issue Jan 13, 2017 · 1 comment
Closed

Reduce StorageSubscription size #10

ocoanet opened this issue Jan 13, 2017 · 1 comment

Comments

@ocoanet
Copy link
Member

ocoanet commented Jan 13, 2017

The StorageSubscription size can be quite large for peers with many subscriptions. The subscription binding keys are serialized in StorageConvertionExtensions.SerializeBindingKeys. This method could be optimized for the very common scenario where binding key parts are numeric values.

For example:

private static void SerializeBindingKey(BinaryWriter binaryWriter, BindingKey bindingKey)
{
    var numericParts = new List<int>(bindingKey.PartCount);
    for (var partIndex = 0; partIndex < bindingKey.PartCount; partIndex++)
    {
        int numericValue;
        if (!int.TryParse(bindingKey.GetPart(partIndex), out numericValue))
            break;

        numericParts.Add(numericValue);
        if (numericParts.Count == bindingKey.PartCount)
        {
            binaryWriter.Write(bindingKey.PartCount | _isNumeric);
            numericParts.ForEach(binaryWriter.Write);
            return;
        }
    }

    binaryWriter.Write(bindingKey.PartCount);
    for (var partIndex = 0; partIndex < bindingKey.PartCount; partIndex++)
    {
        binaryWriter.Write(bindingKey.GetPart(partIndex));
    }
}

Of course, a test should be writen to measure the improvements of this change.

@ltrzesniewski
Copy link
Member

This issue was moved to Abc-Arbitrage/Zebus#71

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants