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

precompute sizes and and simplify BasicProperties presence #890

Merged
merged 2 commits into from
Jul 7, 2020

Conversation

bollhals
Copy link
Contributor

@bollhals bollhals commented Jul 5, 2020

Proposed Changes

There are two changes in this PR.
1)
The size calculations for GetRequiredPayloadBufferSize & GetRequiredBufferSize are now as much precomputed as possible.
E.g.
Before

    public override int GetRequiredBufferSize()
    {
      int bufferSize = 0;
      bufferSize++; // _versionMajor in bytes
      bufferSize++; // _versionMinor in bytes
      bufferSize += WireFormatting.GetTableByteCount(_serverProperties); // _serverProperties in bytes
      bufferSize += 4 + _mechanisms.Length; // _mechanisms in bytes
      bufferSize += 4 + _locales.Length; // _locales in bytes
      return bufferSize;
    }

After

    public override int GetRequiredBufferSize()
    {
      int bufferSize = 10; // bytes for _versionMajor, _versionMinor, length of _mechanisms, length of _locales
      bufferSize += WireFormatting.GetTableByteCount(_serverProperties); // _serverProperties in bytes
      bufferSize += _mechanisms.Length; // _mechanisms in bytes
      bufferSize += _locales.Length; // _locales in bytes
      return bufferSize;
    }

Changed the BasicProperties internals of the present check.
Now whether or not a property is present, is not a field anymore, but a check against != default.

Difference: If a default value is assinged, it is considered not present. Also less fields, smaller memory footprint.

Types of Changes

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

  • Bug fix (non-breaking change which fixes issue #NNNN)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause an observable behavior change in existing systems)
  • Documentation improvements (corrections, new content, etc)
  • Cosmetic change (whitespace, formatting, etc)

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 repositories

@michaelklishin
Copy link
Member

@bollhals these are reasonable changes, thank you. We trust your judgement but for the sake of transparency, how do the allocation numbers change with this modification?

@bollhals
Copy link
Contributor Author

bollhals commented Jul 6, 2020

Before
image

After
image

It's a 8 byte reduction per instance, not much but it's something. I was expecting more as there were 14 bools eliminated.

@michaelklishin michaelklishin merged commit efabd50 into rabbitmq:master Jul 7, 2020
@michaelklishin michaelklishin added this to the 7.0.0 milestone Jul 7, 2020
@michaelklishin
Copy link
Member

Given the muted effectiveness of this change (looks like due to C# compiler optimizations?), let's keep this specific to 7.0. Of course, by 7.0 we might remove API generator entirely but only time will tell. We appreciate @bollhals' ongoing contributions either way 🥇

@bollhals bollhals deleted the apigenimprovements branch March 2, 2021 20:49
@lukebakken lukebakken modified the milestones: 8.0.0, 7.0.0 Mar 8, 2022
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.

3 participants