Skip to content

Conversation

@emmenlau
Copy link
Member

This PR makes a change to how the new buffer size of TMemoryBuffer is computed. In the current implementation, the new size of TMemoryBuffer is computed in a loop, which makes it less readable. This PR replaces the computation of the new size with an explicit formula.

  • Jira ticket at https://issues.apache.org/jira/browse/THRIFT-5114
  • If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
  • Did you squash your changes to a single commit? (not required, but preferred)
  • Did you do your best to avoid breaking changes? If one was needed, did you label the Jira ticket with "Breaking-Change"?
  • If your change does not involve any code, add [skip ci] at the end of your pull request to free up build resources.

@Jens-G
Copy link
Member

Jens-G commented Feb 25, 2020

There's also #2007 ... may I ask to cross-review each others change, resolving any potential interferences?

@emmenlau
Copy link
Member Author

There's also #2007 ... may I ask to cross-review each others change, resolving any potential interferences?

The two changes are unrelated. My change is foremost for better readability of the code. My change also introduces a difference in the allocation size of buffer enlargement. The current implementation computes this based on a relatively hard to understand formula. My change always allocates the next larger power of two, so essentially it doubles the buffer whenever the size is exceeded.

I can not say that my allocation policy is generally better. But it is hopefully easier to understand and maintain.

@cfriedt
Copy link
Contributor

cfriedt commented Feb 26, 2020

I also agree #2007 is unrelated.

@stale
Copy link

stale bot commented Apr 26, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Apr 26, 2020
@cfriedt
Copy link
Contributor

cfriedt commented Apr 27, 2020

Getting pushed back again, sorry.

@stale
Copy link

stale bot commented Apr 27, 2020

This issue is no longer stale. Thank you for your contributions.

@stale stale bot removed the wontfix label Apr 27, 2020
@emmenlau emmenlau force-pushed the bda_simplify_tmemorybuffer_alloc branch from 74e182d to 5d60e81 Compare June 2, 2020 09:34
@emmenlau
Copy link
Member Author

emmenlau commented Jun 2, 2020

Pushed an update, and rebased on latest master.

@emmenlau emmenlau force-pushed the bda_simplify_tmemorybuffer_alloc branch from 5d60e81 to 2156a3c Compare June 2, 2020 14:11
}
avail = available_write() + (static_cast<uint32_t>(new_size) - bufferSize_);
const uint32_t current_used = bufferSize_ - avail;
const uint32_t required_buffer_size = len + current_used;
Copy link
Member

Choose a reason for hiding this comment

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

const?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's one of my clean-code-quirks: I use const wherever possible. I think it makes the code more robust, because none of these variables are expected to change in the remainder of the code.

Would you prefer to remove my strong consting? Then I will not continue to use it in Thrift.

Copy link
Member

@Jens-G Jens-G Jun 3, 2020

Choose a reason for hiding this comment

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

No, my fault, I was under the impression that since avail may change the value can't hardly be const but it is not exactly the way I assumed it is re initialization of the const. So const is fine.

@Jens-G Jens-G closed this in eac4d0c Jun 3, 2020
@emmenlau emmenlau deleted the bda_simplify_tmemorybuffer_alloc branch November 19, 2020 10:27
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