⚡ Bolt: optimize hot paths in WalletService#40
Conversation
- 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>
|
👋 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. |
- 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>
This PR optimizes several hot paths within the
WalletServiceto improve performance and reduce database latency.💡 What:
ProcessPaymentto useINSERT ... ON CONFLICT (reference_id) DO NOTHING. This eliminates a separateSELECTquery, reducing database round-trips and transaction duration, which is critical underSERIALIZABLEisolation.GetExchangeRateare now normalized to uppercase before cache lookup, preventing cache fragmentation.fmt.Sprintfcalls with high-performance string concatenation andstrconvfunctions for generating cache keys, transaction descriptions, and JSON payloads.🎯 Why:
The
WalletServiceis a high-traffic component where every millisecond and database round-trip counts.fmt.Sprintfis 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.goshow:ProcessPaymentcall.🔬 Measurement:
Run benchmarks:
cd back-end && go test -bench=. ./internal/usecase/wallet_service_perf_test.goPR created automatically by Jules for task 14739510270462557626 started by @MethasMP