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

[Data] Avoid memory leak with pyarrow.infer_type on datetime arrays #50403

Merged
merged 32 commits into from
Feb 13, 2025

Conversation

bveeramani
Copy link
Member

Why are these changes needed?

pyarrow.infer_type leaks memory when inferring a datetime array, and this leak can contribute to OOMs. This PR worksaround the issue by manually inferring the type for datetime arrays.

Related issue number

apache/arrow#45493

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Signed-off-by: Balaji Veeramani <[email protected]>
Signed-off-by: Balaji Veeramani <[email protected]>
Signed-off-by: Balaji Veeramani <[email protected]>
Comment on lines +56 to +71
def test_infer_type_does_not_leak_memory(dtype):
# Test for https://github.com/apache/arrow/issues/45493.
column_values = np.zeros(923040, dtype=dtype) # A ~7 MiB column

process = psutil.Process()
gc.collect()
pa.default_memory_pool().release_unused()
before = process.memory_info().rss

_infer_pyarrow_type(column_values)

gc.collect()
pa.default_memory_pool().release_unused()
after = process.memory_info().rss

assert after - before < 1024 * 1024, after - before
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it fail w/o your changes? What's amount of memory leaked per call?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. Like 130 MiB lol

Copy link
Member Author

Choose a reason for hiding this comment

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

If you haven't already, see the repro in the commented issue: apache/arrow#45493

Signed-off-by: Balaji Veeramani <[email protected]>
Signed-off-by: Balaji Veeramani <[email protected]>
@bveeramani bveeramani enabled auto-merge (squash) February 12, 2025 20:55
@github-actions github-actions bot added the go add ONLY when ready to merge, run all tests label Feb 12, 2025
Signed-off-by: Balaji Veeramani <[email protected]>
@github-actions github-actions bot disabled auto-merge February 12, 2025 23:11
@bveeramani bveeramani enabled auto-merge (squash) February 12, 2025 23:12
Signed-off-by: Balaji Veeramani <[email protected]>
@github-actions github-actions bot disabled auto-merge February 12, 2025 23:15
@bveeramani bveeramani enabled auto-merge (squash) February 12, 2025 23:15
@bveeramani bveeramani merged commit f2f5e8e into master Feb 13, 2025
6 checks passed
@bveeramani bveeramani deleted the infer-type-leak branch February 13, 2025 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go add ONLY when ready to merge, run all tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants