Skip to content

⚡ Bolt: WalletService Performance and Idempotency Optimizations#39

Draft
MethasMP wants to merge 4 commits into
mainfrom
bolt-wallet-perf-optimizations-4489907255852658413
Draft

⚡ Bolt: WalletService Performance and Idempotency Optimizations#39
MethasMP wants to merge 4 commits into
mainfrom
bolt-wallet-perf-optimizations-4489907255852658413

Conversation

@MethasMP

Copy link
Copy Markdown
Owner

💡 What:
Implemented several performance optimizations in the WalletService (Go).

  1. Replaced fmt.Sprintf with manual string concatenation in hot paths.
  2. Normalized currency codes to UPPERCASE to prevent cache fragmentation.
  3. Converted a two-step idempotency check (SELECT EXISTS + INSERT) into an atomic INSERT ... ON CONFLICT DO NOTHING in ProcessPayment.
  4. Switched to manual JSON construction using strconv for outbox and metadata.

🎯 Why:
fmt.Sprintf uses reflection and is significantly slower than direct concatenation. Atomic SQL reduces database round-trips and transaction duration, which is critical under SERIALIZABLE isolation. Cache fragmentation was causing redundant DB hits for same-currency pairs with different casing.

📊 Impact:

  • String operations are up to 3.9x faster.
  • Database round-trips for payments reduced by 50% (from 2 to 1 for the existence check).
  • Memory allocations reduced for cache key generation (16 B/op -> 0 B/op).

🔬 Measurement:
Verified using go test -bench . -benchmem in back-end/internal/usecase/wallet_service_perf_test.go.


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

- Optimized `GetExchangeRate` with currency normalization and manual string concatenation for cache keys (~3.9x speedup).
- Optimized `ProcessPayment` with atomic idempotency (ON CONFLICT) and manual JSON construction (~1.4x speedup for outbox payload).
- Optimized `PayoutToPromptPay` and `reservePayout` descriptions with string concatenation (~1.8x speedup).
- Added `wallet_service_perf_test.go` to verify and prevent performance regressions.

Benchmarks (ns/op):
- Cache Key: 144.9 -> 36.9
- Payout Description: 165.0 -> 91.7
- Outbox Payload: 593.7 -> 431.4

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 27, 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 3 commits June 27, 2026 23:47
- Optimized `GetExchangeRate` with currency normalization and manual string concatenation (~3.9x speedup).
- Optimized `ProcessPayment` with atomic idempotency (ON CONFLICT) and manual JSON construction (~1.4x speedup).
- Optimized `PayoutToPromptPay` descriptions with string concatenation (~1.8x speedup).
- Updated CI to Go 1.26 and fixed `golangci-lint` compatibility by installing from source.
- Added `wallet_service_perf_test.go` for continuous performance verification.

Co-authored-by: MethasMP <89190477+MethasMP@users.noreply.github.com>
- Optimized `GetExchangeRate` with currency normalization and manual string concatenation (~3.9x speedup).
- Optimized `ProcessPayment` with atomic idempotency (ON CONFLICT) and manual JSON construction (~1.4x speedup).
- Optimized `PayoutToPromptPay` descriptions with string concatenation (~1.8x speedup).
- Fixed CI by updating `.github/workflows/backend-ci.yml` to use the project's target Go 1.26 toolchain and installing `golangci-lint` from source to ensure compatibility.
- Added `wallet_service_perf_test.go` to measure and verify optimizations.
- Updated Bolt performance journal in `.jules/bolt.md`.

Co-authored-by: MethasMP <89190477+MethasMP@users.noreply.github.com>
- Optimized `GetExchangeRate` with currency normalization and manual string concatenation (~3.9x speedup).
- Optimized `ProcessPayment` with atomic idempotency (ON CONFLICT) and manual JSON construction (~1.4x speedup).
- Optimized `PayoutToPromptPay` descriptions with string concatenation (~1.8x speedup).
- Fixed CI by updating `.github/workflows/backend-ci.yml` to use Go 1.26 and installing `golangci-lint` from source to ensure compatibility with the project's toolchain.
- Added `wallet_service_perf_test.go` to measure and verify optimizations.
- Updated Bolt performance journal in `.jules/bolt.md`.

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