Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance issues with multi-currency setup #1530

Open
jakubkottnauer opened this issue Dec 11, 2024 · 1 comment
Open

Performance issues with multi-currency setup #1530

jakubkottnauer opened this issue Dec 11, 2024 · 1 comment
Labels
💻 Self Hosting Issues pertaining to self-hosted versions of Maybe ⚡ Performance Performance issues to address

Comments

@jakubkottnauer
Copy link
Contributor

I have been using Maybe with a non-trivial amount of data (10 000 account_entries, 40 accounts, 5 different currencies) since the beginning and have always observed performance issues. I have finally found the time to replicate my production database in my local environment and do some poking around. Thought I'd create this issue to gather my findings.

Note that all the timings below are are measured on my beefy MacBook Pro. My actual production instance is running on a Synology NAS where all the loading times are about 4 times worse 😄

Rendering the /transactions page

About 50% of the time here is spent rendering the Income and Expense statistics at the top of the page, caused by the currency conversion in Money.exchange_to (this line

exchange_rate = store.find_rate(from: iso_code, to: other_iso_code, date: date)&.rate || fallback_rate
).

Some ideas to improve this:

  • we could prefetch all the necessary exchange rates in a single query, store them in a hash map and use that instead of querying the database on each conversion
  • alternatively we could store converted_amount in the account_entries table

Just to get an idea of big of an impact this has; here is a before/after after I have replaced line 49 with exchange_rate = 1 (= skipping the exchange rate query)

Before:
Completed 200 OK in 2191ms (Views: 536.7ms | ActiveRecord: 360.0ms (3012 queries, 1571 cached) | GC: 392.0ms)

After:
Completed 200 OK in 974ms (Views: 344.1ms | ActiveRecord: 133.6ms (480 queries, 92 cached) | GC: 286.7ms)

Rendering the dashboard (/) page

While this page would also benefit from the optimization mentioned above, there's another fun issue I've found - removing the entire <% if self_hosted? %> check from the top of the dashboard.html.erb view (

<% if self_hosted? %>
) significantly speeds up the rendering of the page.

Seems like checking the Synth state blocks rendering (?)

Before:
Completed 200 OK in 1155ms (Views: 898.7ms | ActiveRecord: 98.5ms (439 queries, 52 cached) | GC: 71.2ms)

After:
Completed 200 OK in 515ms (Views: 296.9ms | ActiveRecord: 89.3ms (439 queries, 52 cached) | GC: 70.4ms)

Sidebar

All of the individual accounts in the sidebar are still rendered even when the account type is collapsed (

<% group.children.sort_by(&:name).each do |account_value_node| %>
). Only rendering them when the section is expanded would provide a significant boost:

Before:
Rendered layouts/_sidebar.html.erb (Duration: 210.2ms | GC: 28.4ms)

After:
Rendered layouts/_sidebar.html.erb (Duration: 115.1ms | GC: 7.4ms)

Wrap up

That's it for today, I hope you find this useful @zachgoll! In this first pass I tried to focus on the biggest offenders/low hanging fruit. Will be more than happy to dig around again in a few weeks.

@zachgoll
Copy link
Collaborator

@jakubkottnauer very helpful findings, appreciate this write-up! Looks like some of these are fairly straightforward fixes.

I won't have much time to tackle these in the near-term due to some broader feature work, but I definitely want to do a performance overhaul at some point soon. The initial build of the app has admittedly been focused mostly on sketching out the business logic, so performance issues have definitely began to bubble up.

@zachgoll zachgoll added 💡 Improvement Improvements to an existing feature or flow ⚡ Performance Performance issues to address and removed 💡 Improvement Improvements to an existing feature or flow labels Dec 12, 2024
@zachgoll zachgoll added the 💻 Self Hosting Issues pertaining to self-hosted versions of Maybe label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 Self Hosting Issues pertaining to self-hosted versions of Maybe ⚡ Performance Performance issues to address
Projects
None yet
Development

No branches or pull requests

2 participants