Skip to content

Remove redundant allocations #477

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

Merged
merged 2 commits into from
Sep 20, 2018
Merged

Conversation

Pliner
Copy link
Contributor

@Pliner Pliner commented Sep 20, 2018

Proposed Changes

This PR removes several unneccessary allocations:

  1. Enumerator of List.
  2. Encoding inside BinaryReader and BinaryWriter.

Types of Changes

What types of changes does your code introduce to this project?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes issue #NNNN)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (correction or otherwise)
  • Cosmetics (whitespace, appearance)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating
the PR. If you're unsure about any of them, don't hesitate to ask on the
mailing list. We're here to help! This is simply a reminder of what we are
going to look for before merging your code.

  • I have read the CONTRIBUTING.md document
  • I have signed the CA (see https://cla.pivotal.io/sign/rabbitmq)
  • All tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in related reposi
    If this is a relatively large or complex change, kick off the discussion by
    explaining why you chose the solution you did and what alternatives you
    considered, etc.
    tories

Further Comments

Producer.cs

    public static class EntryPoint
    {
        public static void Main(string[] args)
        {
            var connectionFactory = new ConnectionFactory();
            using (var connection = connectionFactory.CreateConnection())
            {
                using (var model = connection.CreateModel())
                {
                    model.ExchangeDeclare("Exchange", "direct", true);
                    for (var i = 0; i < 10000; ++i)
                    {
                        model.BasicPublish("Exchange", "#", body: new byte[100000]);
                    }
                }
            }   

            Console.ReadKey();
        }
    }

Before
Before.zip

After
After.zip

As you can see, after this change amount of allocated objects dropped by 1/4. Also it seems the next major improvement can be a replace of NetworkBinaryReader and NetworkBinaryWriter, which will not allocate so much trash 😜

@kjnilsson kjnilsson merged commit be28817 into rabbitmq:master Sep 20, 2018
@kjnilsson
Copy link
Contributor

Thanks!

@Pliner Pliner deleted the redundant-allocations branch September 20, 2018 09:05
@kjnilsson
Copy link
Contributor

This change should be in https://www.nuget.org/packages/RabbitMQ.Client/6.0.0-pre3

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.

2 participants