⚡ Bolt: Optimize WalletService performance and idempotency#41
Conversation
- Implement atomic idempotency in `ProcessPayment` using `ON CONFLICT DO NOTHING`. - Replace `fmt.Sprintf` with string concatenation for cache keys and descriptions. - Use `strconv` and manual concatenation for performant and safe JSON construction. - Hoist `strings.ToUpper` in `GetExchangeRate` to avoid redundant calls. - Add `wallet_service_perf_test.go` to measure and verify optimizations. Performance impact: - Cache key generation: ~132ns -> ~38ns (~3.5x faster) - JSON payload construction: ~979ns -> ~436ns (~2.2x faster) - Reduced database roundtrips for payment processing. Co-authored-by: MethasMP <89190477+MethasMP@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
This PR optimizes several hot paths in
WalletServiceto reduce latency and database load.💡 What
ProcessPayment, replaced the two-stepSELECT EXISTS+INSERTwith a singleINSERT ... ON CONFLICT DO NOTHING. This reduces database roundtrips and serialization conflict risks.fmt.Sprintfwith manual string concatenation inGetExchangeRate,ProcessPayment, andPayoutToPromptPay.ProcessPayment, usedstrconv.FormatFloatandstrconv.Quotefor manual JSON building, which is faster thanfmt.Sprintfand safer against special characters in merchant names.internal/usecase/wallet_service_perf_test.goto provide a baseline and prevent future performance regressions.🎯 Why
Reflection-heavy functions like
fmt.Sprintfand multiple database roundtrips add unnecessary overhead to high-frequency payment and exchange rate operations.📊 Impact
🔬 Measurement
Run
cd back-end && go test -bench . internal/usecase/wallet_service_perf_test.goto verify the micro-benchmarks.PR created automatically by Jules for task 9180414245420419233 started by @MethasMP