Skip to content

GH-40898: [C#] Do not import length-zero buffers from C Data Interface Arrays#41054

Merged
CurtHagenlocher merged 3 commits intoapache:mainfrom
paleolimbot:csharp-null-buffers
Apr 7, 2024
Merged

GH-40898: [C#] Do not import length-zero buffers from C Data Interface Arrays#41054
CurtHagenlocher merged 3 commits intoapache:mainfrom
paleolimbot:csharp-null-buffers

Conversation

@paleolimbot
Copy link
Copy Markdown
Member

@paleolimbot paleolimbot commented Apr 6, 2024

Rationale for this change

When implementing integration tests for nanoarrow, it was observed that C# never released arrays where array->buffers[i] was NULL (including any buffers of any recursive child arrays). This is allowed ( https://arrow.apache.org/docs/format/CDataInterface.html#c.ArrowArray.buffers ); however, every other implementation appears to allocate even for length zero buffers (including nanoarrow after apache/arrow-nanoarrow#399 ).

What changes are included in this PR?

AddMemory() is replaced with ArrowBuffer.Empty if the length of the imported buffer would have been 0 bytes. For other buffers (or anywhere I saw dereferencing a buffer pointer), I added a Debug.Assert just to be sure.

Are these changes tested?

I'm not sure what the best way to test them is! They won't be tested in the nanoarrow integration tests since at the point that they run, nanoarrow will no longer export arrays that would trigger this.

Are there any user-facing changes?

No

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2024

⚠️ GitHub issue #40898 has been automatically assigned in GitHub to PR creator.

@paleolimbot paleolimbot marked this pull request as ready for review April 6, 2024 23:47
Copy link
Copy Markdown
Contributor

@CurtHagenlocher CurtHagenlocher left a comment

Choose a reason for hiding this comment

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

Thanks for doing this; I'm in the middle of a move and hadn't yet had a chance to look into this.

@paleolimbot
Copy link
Copy Markdown
Member Author

No problem!

@conbench-apache-arrow
Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 8fd3ce9.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 2 possible false positives for unstable benchmarks that are known to sometimes produce them.

@paleolimbot paleolimbot deleted the csharp-null-buffers branch April 9, 2024 16:17
vibhatha pushed a commit to vibhatha/arrow that referenced this pull request May 25, 2024
…terface Arrays (apache#41054)

### Rationale for this change

When implementing integration tests for nanoarrow, it was observed that C# never released arrays where `array->buffers[i]` was `NULL` (including any buffers of any recursive child arrays). This is allowed ( https://arrow.apache.org/docs/format/CDataInterface.html#c.ArrowArray.buffers ); however, every other implementation appears to allocate even for length zero buffers (including nanoarrow after apache/arrow-nanoarrow#399 ).

### What changes are included in this PR?

`AddMemory()` is replaced with `ArrowBuffer.Empty` if the length of the imported buffer would have been 0 bytes. For other buffers (or anywhere I saw dereferencing a buffer pointer), I added a `Debug.Assert` just to be sure.

### Are these changes tested?

I'm not sure what the best way to test them is! They won't be tested in the nanoarrow integration tests since at the point that they run, nanoarrow will no longer export arrays that would trigger this.

### Are there any user-facing changes?

No
* GitHub Issue: apache#40898

Authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
Signed-off-by: Curt Hagenlocher <curt@hagenlocher.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants