Skip to content

⚡ Bolt: optimize hot paths in WalletService#40

Draft
MethasMP wants to merge 3 commits into
mainfrom
bolt/optimize-wallet-service-hot-paths-14739510270462557626
Draft

⚡ Bolt: optimize hot paths in WalletService#40
MethasMP wants to merge 3 commits into
mainfrom
bolt/optimize-wallet-service-hot-paths-14739510270462557626

Conversation

@MethasMP

Copy link
Copy Markdown
Owner

This PR optimizes several hot paths within the WalletService to improve performance and reduce database latency.

💡 What:

  • Atomic Idempotency: Refactored ProcessPayment to use INSERT ... ON CONFLICT (reference_id) DO NOTHING. This eliminates a separate SELECT query, reducing database round-trips and transaction duration, which is critical under SERIALIZABLE isolation.
  • Cache Normalization: Currency codes in GetExchangeRate are now normalized to uppercase before cache lookup, preventing cache fragmentation.
  • String Formatting Optimizations: Replaced expensive fmt.Sprintf calls with high-performance string concatenation and strconv functions for generating cache keys, transaction descriptions, and JSON payloads.

🎯 Why:

The WalletService is a high-traffic component where every millisecond and database round-trip counts. fmt.Sprintf is known to be slow in Go due to reflection and interface allocations. Atomic SQL operations reduce the window for serialization conflicts.

📊 Impact:

Benchmarks in back-end/internal/usecase/wallet_service_perf_test.go show:

  • Cache Key Generation: ~130ns -> ~37ns per op (~3.5x faster).
  • JSON Formatting: ~980ns -> ~436ns per op (~2.2x faster).
  • Database Latency: Reduced by 1 round-trip for every ProcessPayment call.

🔬 Measurement:

Run benchmarks: cd back-end && go test -bench=. ./internal/usecase/wallet_service_perf_test.go


PR created automatically by Jules for task 14739510270462557626 started by @MethasMP

- Normalize currency codes and use string concatenation for cache keys in GetExchangeRate (~3.5x faster).
- Implement atomic idempotency with ON CONFLICT DO NOTHING in ProcessPayment, reducing DB round-trips.
- Replace fmt.Sprintf with performant string concatenation and strconv for JSON/descriptions (~2.2x faster).
- Add wallet_service_perf_test.go to prevent future regressions.
- Update .jules/bolt.md with critical learnings.

Co-authored-by: MethasMP <89190477+MethasMP@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
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.

@supabase

supabase Bot commented Jun 28, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project iybequvtfiqoexnhfwvb because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

google-labs-jules Bot and others added 2 commits June 28, 2026 23:46
- Optimize WalletService hot paths (GetExchangeRate, ProcessPayment, PayoutToPromptPay).
- Achieve ~3.5x speedup in cache key generation and ~2.2x in JSON formatting.
- Implement atomic SQL idempotency with ON CONFLICT DO NOTHING.
- Fix CI failures by aligning Go version to 1.26 in workflows and Dockerfile.
- Fix golangci-lint compatibility by using manual install and GOWORK=off.
- Add and verify benchmarks in wallet_service_perf_test.go.

Co-authored-by: MethasMP <89190477+MethasMP@users.noreply.github.com>
- Implement atomic SQL idempotency with ON CONFLICT DO NOTHING in ProcessPayment.
- Optimize hot paths (GetExchangeRate, PayoutToPromptPay) with string concatenation (~3.5x faster).
- Normalize currency codes in GetExchangeRate to prevent cache fragmentation.
- Fix CI Go 1.26 compatibility by updating workflows and Dockerfile.
- Fix golangci-lint mismatch by using manual install and GOWORK=off.
- Add benchmarks in wallet_service_perf_test.go.

Co-authored-by: MethasMP <89190477+MethasMP@users.noreply.github.com>
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