Speed up 'BudgetsController#show'
Closed
TE
5mo ago+113+113+012345678901234567890123456789-36-36-01234567890123456789
I am currently very interested in this project. However, its slow response time is a drawback. Consequently, after investigating the project using Skylight, I decided to optimize "BudgetsController#show"—the specific endpoint identified as having a slow response time.
Summary
Speed up BudgetsController#show by cutting repeated per-category work in models/helpers and reducing Sentry overhead on hot paths so production traces reflect real app time.
- BudgetCategory: Memoize
actual_spending,available_to_spend, andpercent_of_budget_spent; replace per-call SQL insubcategorieswith an in-memory filter over the already-loadedbudget.budget_categoriesassociation. - Budget: Memoize
allocated_spending; route income helpers through the memoizedincome_statementinstead offamily.income_statement. - BudgetsHelper: Derive
budget_has_over_budget?frombudget_categories_view_state[:over_budget_count]instead of a second full-category pass. - Sentry: Disable log forwarding by default;
traces_samplerskips/budgets/*,/reports/*, dashboard, and Rails internals; env-tunable sample rates. - Production: Optional
Server-TimingwhenSERVER_TIMING=true.
Test plan
- Open Budgets from the sidebar; use prev/next, Today, and month picker.
- [ x] Confirm category cards (spent %, over-budget styling, subcategories with parent budget).
- [ x] Compare latency with
SERVER_TIMING=trueif needed. - [ x] Confirm Sentry transaction volume for
/budgets/*drops while errors still capture.
Summary by CodeRabbit
-
Performance Improvements
- Implemented caching for budget calculations to reduce computational overhead on repeated requests.
-
Configuration
- Made error tracking and performance monitoring settings configurable via environment variables for greater operational control.