Skip to content

test: create framework for testing memory#4921

Merged
wjones127 merged 15 commits intolance-format:mainfrom
wjones127:test/memory-tests
Nov 6, 2025
Merged

test: create framework for testing memory#4921
wjones127 merged 15 commits intolance-format:mainfrom
wjones127:test/memory-tests

Conversation

@wjones127
Copy link
Copy Markdown
Contributor

@wjones127 wjones127 commented Oct 9, 2025

Adds a new integration test resource_test which contains a utility for making assertions about memory use with a span. This needs to be in a separate integration tests because it hooks into the global memory allocator, and doing that for all tests would probably make them quite slow.

Here's an example of how this can be used:

let alloc_tracker = AllocTracker::new();
{
    let _guard = alloc_tracker.enter();
    // Do something that allocates, even in async tasks
}
let stats = alloc_tracker.stats();
assert_lt!(stats.max_bytes_allocated, 100_000_000, "Used more than 100MB");
assert_eq!(stats.total_bytes_allocated, stats.total_bytes_deallocated, "No memory leaked");

Closes #4761

@github-actions github-actions Bot added the chore label Oct 9, 2025
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Oct 9, 2025

Codecov Report

❌ Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.69%. Comparing base (9994f69) to head (26af669).
⚠️ Report is 26 commits behind head on main.

Files with missing lines Patch % Lines
rust/lance-core/src/cache.rs 83.33% 1 Missing ⚠️
rust/lance-datafusion/src/datagen.rs 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4921      +/-   ##
==========================================
+ Coverage   81.38%   81.69%   +0.31%     
==========================================
  Files         333      334       +1     
  Lines      130056   132747    +2691     
  Branches   130056   132747    +2691     
==========================================
+ Hits       105847   108454    +2607     
+ Misses      20654    20649       -5     
- Partials     3555     3644      +89     
Flag Coverage Δ
unittests 81.69% <91.66%> (+0.31%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread rust/lance-index/src/scalar/bitmap.rs Outdated
Comment thread rust/lance-index/src/scalar/bitmap.rs Outdated
@wjones127 wjones127 changed the title test: create framework for testing memory and io test: create framework for testing memory Nov 5, 2025
@wjones127 wjones127 marked this pull request as ready for review November 5, 2025 22:12
stats.max_bytes_allocated,
(batch_size * 2) as isize,
"Max memory usage exceeded"
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if it would make sense to wrap this up in a macro. Would that promote more widespread usage?

#[maxallocs=10*1024*1024]
{
        let tmp_dir = tempfile::tempdir().unwrap();
        let tmp_path = tmp_dir.path().to_str().unwrap();
        let _dataset = InsertBuilder::new(tmp_path)
            .execute_stream(data)
            .await
            .unwrap();
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We can add that later if we find it simplifies things. Will be easier to see once we have more tests in here and see what patterns are repeating.

@wjones127
Copy link
Copy Markdown
Contributor Author

Had to disable this for MacOS. We can implement a version that is cross platform in a future PR.

@wjones127 wjones127 merged commit 70f6f33 into lance-format:main Nov 6, 2025
34 of 36 checks passed
@wjones127 wjones127 deleted the test/memory-tests branch November 6, 2025 21:40
jackye1995 pushed a commit to jackye1995/lance that referenced this pull request Jan 21, 2026
Adds a new integration test `resource_test` which contains a utility for
making assertions about memory use with a span. This needs to be in a
separate integration tests because it hooks into the global memory
allocator, and doing that for all tests would probably make them quite
slow.

Here's an example of how this can be used:

```rust
let alloc_tracker = AllocTracker::new();
{
    let _guard = alloc_tracker.enter();
    // Do something that allocates, even in async tasks
}
let stats = alloc_tracker.stats();
assert_lt!(stats.max_bytes_allocated, 100_000_000, "Used more than 100MB");
assert_eq!(stats.total_bytes_allocated, stats.total_bytes_deallocated, "No memory leaked");
```

Closes lance-format#4761
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add utility to test memory usage in integration tests

4 participants