Skip to content

⚡ Bolt: optimize MaybeNullBufferBuilder::take_n#286

Open
Dandandan wants to merge 1 commit intomainfrom
bolt-optimize-null-builder-take-n-4505990081372878565
Open

⚡ Bolt: optimize MaybeNullBufferBuilder::take_n#286
Dandandan wants to merge 1 commit intomainfrom
bolt-optimize-null-builder-take-n-4505990081372878565

Conversation

@Dandandan
Copy link
Copy Markdown
Owner

This PR optimizes the `take_n` method in `MaybeNullBufferBuilder`, which is a critical part of the group-by aggregation engine in DataFusion. By replacing a manual bit-by-bit loop with optimized bitwise operations from Arrow, we achieve a massive performance improvement in emitting batches of results.

Measurements on 100k rows with 8192 batch size:

  • No nulls: 12ms -> 18µs (~660x faster)
  • With nulls: 54ms -> 1.5ms (~34x faster)

PR created automatically by Jules for task 4505990081372878565 started by @Dandandan

💡 What:
Optimized the \`take_n\` method in \`MaybeNullBufferBuilder\` by:
1. Adding a fast path for when no nulls are present.
2. Replacing the manual bit-by-bit loop with optimized Arrow bitwise operations (\`NullBuffer::slice\` and \`NullBufferBuilder::append_buffer\`).

🎯 Why:
The previous implementation iterated over every bit individually, which is extremely slow for large batch sizes common in DataFusion.

📊 Impact:
- ~660x faster for non-null cases.
- ~34x faster for cases with nulls.

🔬 Measurement:
Verified with a benchmark test (see \`.jules/bolt.md\` for details). Existing group-by tests pass.

Co-authored-by: Dandandan <163737+Dandandan@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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.

1 participant