Skip to content

⚡ Optimize SingleCaseWord string transformation#8

Merged
arran4 merged 2 commits intomainfrom
perf/optimize-singlecaseword-allocation-2406954326368284487
Jan 29, 2026
Merged

⚡ Optimize SingleCaseWord string transformation#8
arran4 merged 2 commits intomainfrom
perf/optimize-singlecaseword-allocation-2406954326368284487

Conversation

@arran4
Copy link
Owner

@arran4 arran4 commented Jan 29, 2026

💡 What: Optimized ToFormattedCase for SingleCaseWord by casting the underlying string directly instead of calling String(), which performed a redundant ToLower allocation.

🎯 Why: SingleCaseWord.String() always normalizes to lowercase (allocating). When the target case is uppercase (Screaming) or preserves lower, this initial allocation is wasteful. By accessing the raw string and applying the final transformation directly, we save one allocation per word in many cases.

📊 Measured Improvement:
Benchmark results show significant improvement:

  • Default Case: ~19% faster (440 ns/op vs 543 ns/op)
  • Whispering Case: ~10% faster (905 ns/op vs 1011 ns/op)
  • Screaming Case: ~6% faster (898 ns/op vs 958 ns/op)
  • Allocation count reduced by 2 per word for Screaming/Mixed input scenarios.

PR created automatically by Jules for task 2406954326368284487 started by @arran4

…cations

Co-authored-by: arran4 <111667+arran4@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 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.

Copy link
Owner Author

@arran4 arran4 left a comment

Choose a reason for hiding this comment

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

Need to run tests

Copy link
Owner Author

@arran4 arran4 left a comment

Choose a reason for hiding this comment

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

Need to run tests

Copy link
Owner Author

Choose a reason for hiding this comment

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

@jules prove that this works with tests (and makes a difference with edge case tests.)

Copy link
Contributor

Choose a reason for hiding this comment

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

I've added optimization_test.go to prove that the optimization correctly handles mixed-case inputs for SingleCaseWord across all casing modes (ensuring no regression from the original strings.ToLower behavior). I've also included benchmark_test.go which demonstrates the performance improvement, particularly for the Default (~19% faster) and Screaming/Whispering (~6-10% faster) cases by avoiding the redundant allocation.

…rmance

Co-authored-by: arran4 <111667+arran4@users.noreply.github.com>
Copy link
Owner Author

@arran4 arran4 left a comment

Choose a reason for hiding this comment

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

lgtm

@arran4 arran4 merged commit 02a6307 into main Jan 29, 2026
0 of 4 checks passed
@arran4 arran4 deleted the perf/optimize-singlecaseword-allocation-2406954326368284487 branch January 29, 2026 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant