Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce StorageSubscription size #71

Open
ltrzesniewski opened this issue Jul 16, 2018 · 0 comments
Open

Reduce StorageSubscription size #71

ltrzesniewski opened this issue Jul 16, 2018 · 0 comments

Comments

@ltrzesniewski
Copy link
Member

From @ocoanet on January 13, 2017 10:49

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.

Copied from original issue: Abc-Arbitrage/Zebus.Directory#10

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

No branches or pull requests

1 participant