Skip to content

Conversation

@bkietz
Copy link
Member

@bkietz bkietz commented Aug 5, 2019

@wesm ChunkedBinaryBuilder was increasing capacity by the growth factor on every call to Reserve. Now it will only do so if added capacity is required

@wesm
Copy link
Member

wesm commented Aug 5, 2019

Can you add a unit test to verify the desired behavior?

@codecov-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@7aefa50). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #5016   +/-   ##
=========================================
  Coverage          ?   89.17%           
=========================================
  Files             ?      727           
  Lines             ?   102887           
  Branches          ?        0           
=========================================
  Hits              ?    91754           
  Misses            ?    11133           
  Partials          ?        0
Impacted Files Coverage Δ
cpp/src/arrow/array/builder_binary.cc 85.55% <100%> (ø)
cpp/src/arrow/array/builder_binary.h 92.92% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7aefa50...a5398da. Read the comment docs.

for (int i = 0; i < 8; ++i) {
ASSERT_OK(builder_->Reserve(chunksize / 2));
}
// no new memory will be allocated since capacity was sufficient for the loop's
Copy link
Member

Choose a reason for hiding this comment

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

How is that? We're reserving 4.5 * chunksize total, no?

Copy link
Member

Choose a reason for hiding this comment

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

In between Reserve calls, no data is appended to the builder, so there is no need to allocate any additional memory.

If you look at the bug report in ARROW-6060 the issue appears to be that memory was being allocated when there was no need.

Copy link
Member

Choose a reason for hiding this comment

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

To review the docstring for Reserve

  /// \brief Ensure that there is enough space allocated to add the indicated
  /// number of elements without any further calls to Resize. Overallocation is
  /// used in order to minimize the impact of incremental Reserve() calls.
  ///
  /// \param[in] additional_capacity the number of additional array values
  /// \return Status

So if there is already enough memory allocated then Reserve should be a no-op

Copy link
Member

Choose a reason for hiding this comment

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

(it might be worth stating in the docstring that calls to Reserve are not cumulative)

Copy link
Member

Choose a reason for hiding this comment

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

(it might be worth stating in the docstring that calls to Reserve are not cumulative)

Really? They are. It's the (confusing) difference between Resize and Reserve.

Copy link
Member Author

Choose a reason for hiding this comment

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

@wesm I've added a note to the docstring

Copy link
Member

@wesm wesm Aug 6, 2019

Choose a reason for hiding this comment

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

This is a good opportunity to clarify the docstring if there is still confusion.

Reserve: pre-allocate space for an absolute, additional amount of data (prior calls to Reserve are not taken into consideration, so Reserve(1000)->Reserve(2000) is the same as Reserve(2000))
Resize: pre-allocate space for an absolute amount of data (regardless of how much has already been appended)

As we've seen here getting the behavior of Reserve wrong has made the 0.14.x release basically unusable for a number of users, so there are consequences to this

Copy link
Contributor

Choose a reason for hiding this comment

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

@bkietz is it possible to have a more aggressive test, e.g. one that uses 16mb in the normal case and 16g in the falling one?

Copy link
Member Author

Choose a reason for hiding this comment

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

@fsaintjacques in the failing case to balloon to 16G all I'd need to do is increase the loop max; the calls to Reserve would continue increasing capacity by the growth factor (1.5) until we run out of memory. I'm not sure what merit increasing the test's scale has

Copy link
Member

Choose a reason for hiding this comment

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

Agreed with @bkietz. We don't need to test to crash, just fail, if Reserve() is buggy.

@wesm wesm changed the title ARROW-6060: [C++] ChunkedBinaryBuilder should only grow when necessary ARROW-6060: [C++] ChunkedBinaryBuilder should only grow when necessary, address runaway memory use in Parquet binary column read Aug 6, 2019
Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

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

+1, LGTM. Will merge if CI green.

@pitrou pitrou closed this in 49badd2 Aug 7, 2019
@wesm
Copy link
Member

wesm commented Aug 7, 2019

I checked the memory use script from the JIRA issue and peak memory use is back in line with expectations

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.

5 participants