Skip to content

GH-55281: [C++][Gandiva] Release arena memory per row for any function with context #55281

Open

Description

@dmitry-chirkov-dremio

Describe the bug, including details regarding any error messages, version, and platform.

Gandiva releases the arena after each row only if some function returns a string. has_arena_allocs_ is set only for binary-like return types in BuildFunctionCall.

levenshtein returns int32 but uses arena memory: (shorter_len + 1) * 2 * sizeof(int) bytes per row. In levenshtein(f0, f1) this memory is kept until Evaluate returns. In levenshtein(upper(f0), upper(f1)) it is released after each row.

To reproduce:

  1. Make 262,144 rows, two utf8 columns, 16 chars each.
  2. Build a projector with levenshtein(f0, f1).
  3. Call Evaluate. Compare arrow::default_memory_pool()->total_bytes_allocated() before and after.

Expected: about 1 MB (the output buffers and one arena chunk).
Actual: 36,876,288 bytes. Memory grows with rows x string length. Results are correct. No crash.

Bigger batch, 2,097,152 rows of 64 chars: 1,178 MiB from the arena, peak RSS 1.6 GB.

Update: this also affects external functions. Any function that gets the execution context (kNeedsContext) can take arena memory. If it does not return a string, that memory is kept until the end of the batch. Test: an external C function that copies 64 bytes into the arena and returns int32. 262,144 rows: 17,858,560 bytes from the arena. Expected: about 1 MB.

AI tools helped with the investigation.

Component(s)

C++, Gandiva

Activity

  1. dmitry-chirkov-dremio commented on Oct 27, 2026

    @dmitry-chirkov-dremio
    ContributorAuthor

    take

  2. dmitry-chirkov-dremio commented on Oct 27, 2026

    @dmitry-chirkov-dremio
    ContributorAuthor

    Side discovery from working on #55278

  3. added 4 commits that reference this issue on Oct 27, 2026
  4. changed the title [-][C++][Gandiva] Arena memory is not released per row when no function in the expression returns a string[/-] [+]GH-55281: [C++][Gandiva] Release arena memory per row for any function with context[/+] on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions