Skip to content
This repository was archived by the owner on Aug 2, 2026. It is now read-only.

⚡ Bolt: replace strings.Builder WriteString(Sprintf) with Fprintf - #29

Open
srimon12 wants to merge 1 commit into
mainfrom
bolt/optimize-string-builder-formatting-13745653911017690048
Open

⚡ Bolt: replace strings.Builder WriteString(Sprintf) with Fprintf#29
srimon12 wants to merge 1 commit into
mainfrom
bolt/optimize-string-builder-formatting-13745653911017690048

Conversation

@srimon12

@srimon12 srimon12 commented Jun 18, 2026

Copy link
Copy Markdown
Owner

💡 What: Replaced builder.WriteString(fmt.Sprintf(...)) with fmt.Fprintf(&builder, ...) across the codebase, particularly in internal/cli/commands/executor.go and internal/dump/dump.go.

🎯 Why: In Go, fmt.Sprintf allocates a new string on the heap. When immediately passed to WriteString, this intermediate string is briefly created and then discarded, creating unnecessary work for the garbage collector. fmt.Fprintf writes directly to the strings.Builder (which implements io.Writer), avoiding this allocation completely.

📊 Impact: Reduces memory allocations during query plan generation and database dumping. Micro-benchmarks typically show a 5-10% speed improvement for formatting and a significant reduction in allocs/op for this specific pattern.

🔬 Measurement: Tested locally via Go benchmark to confirm reduction in allocs/op. All existing unit tests pass via go test ./....


PR created automatically by Jules for task 13745653911017690048 started by @srimon12

Summary by CodeRabbit

  • Refactor
    • Internal performance optimizations to query plan generation and data export operations through improved string handling efficiency.

This refactoring replaces occurrences of `builder.WriteString(fmt.Sprintf(...))` with `fmt.Fprintf(&builder, ...)`.
The former allocates an intermediate string on the heap, which incurs unnecessary GC overhead.
The latter writes the formatted string directly into the builder's buffer, improving memory efficiency and performance.

Co-authored-by: srimon12 <33979603+srimon12@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.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 10c350df-939c-4797-9dc1-9d929c994235

📥 Commits

Reviewing files that changed from the base of the PR and between 7c85208 and 6a85b0a.

📒 Files selected for processing (3)
  • .jules/bolt.md
  • internal/cli/commands/executor.go
  • internal/dump/dump.go

📝 Walkthrough

Walkthrough

Replaces builder.WriteString(fmt.Sprintf(...)) with fmt.Fprintf(&builder, ...) across internal/cli/commands/executor.go (all ExplainResult plan output cases) and internal/dump/dump.go (seven call sites spanning INSERT, USING, header comments, map serialization, CREATE COLLECTION, and quantization). Adds a dated note to .jules/bolt.md documenting this pattern.

Changes

fmt.Fprintf String Builder Refactor

Layer / File(s) Summary
Documentation note for fmt.Fprintf pattern
.jules/bolt.md
Adds a 2025-02-28 entry recording the recommendation to use fmt.Fprintf(&builder, ...) over builder.WriteString(fmt.Sprintf(...)).
dump.go fmt.Fprintf refactor
internal/dump/dump.go
Switches seven WriteString(fmt.Sprintf(...)) sites to fmt.Fprintf across INSERT INTO … VALUES, USING clause, dump header comments, serializeMap key emission, buildDumpCreateLine vector-type lines, scalar quantile, and turboquant bits sub-clauses.
executor.go ExplainResult fmt.Fprintf refactor
internal/cli/commands/executor.go
Converts all WriteString(fmt.Sprintf(...)) calls within ExplainResult's plan builder to fmt.Fprintf across all ast.*Stmt cases: SHOW/CREATE/ALTER/DROP COLLECTION, INSERT, SELECT, SCROLL, and the full QUERY planning path (ORDER BY, SAMPLE, default modes, USING, WITH params, WHERE, OFFSET, SCORE THRESHOLD, LOOKUP, grouping, rerank, recommend/context/discover, CTEs, prefetch, fusion, formula, DELETE, UPDATE, CREATE INDEX).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 No more Sprintf in my Write,
I Fprintf direct — what a delight!
Less allocation, less GC fuss,
The builder and I, riding the bus.
Fewer bounces, cleaner hops — ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main optimization: replacing WriteString(Sprintf) with Fprintf for strings.Builder, which is the primary change across all modified files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bolt/optimize-string-builder-formatting-13745653911017690048

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant