Skip to content

Optimize the proposals loading performance#13701

Merged
andreslucena merged 9 commits intodevelopfrom
fix/proposals-author-cell
Dec 9, 2024
Merged

Optimize the proposals loading performance#13701
andreslucena merged 9 commits intodevelopfrom
fix/proposals-author-cell

Conversation

@alecslupu
Copy link
Copy Markdown
Contributor

@alecslupu alecslupu commented Nov 28, 2024

🎩 What? Why?

Recently Decidim Barcelona had some issues with the proposals, and in an effort of optimizing the page, i could observe that the proposal cell is dependent of author , which increased a lot the memory and cpu usage. In an attempt to optimize this, we noticed that Proposal cell cannot be optimally cached due to author and current user relation. to split that we decided to move the tooltip to an AJAX approach. Doing this, i could observe the following improvements using AB (aiming 100 requests, with a concurrency of 5)

List mode
Before Before after Ratio
no cache cache cache
Time for tests 800 337 228 -0.60%
Requests per second 0.12 0.30 0.44 -0.31%
Grid mode
Before Before after Ratio
no cache cache cache
Time for tests 815 529 216 -0.32%
Requests per second 0.12 0.19 0.46 -0.59%

Additionally, i have seen there is no cache that is being used

📌 Related Issues

Link your PR to an issue

  • Related to #?
  • Fixes #?

Testing

Describe the best way to test or validate your PR.

📷 Screenshots

more details here: https://docs.google.com/document/d/1vR5ck119qNZ1ds6qniefxfgYVC0-voKOWoL-FcsLf9E/edit?usp=sharing

♥️ Thank you!

@alecslupu alecslupu added the type: fix PRs that implement a fix for a bug label Nov 28, 2024
github-actions[bot]
github-actions bot previously approved these changes Nov 28, 2024
github-actions[bot]
github-actions bot previously approved these changes Nov 28, 2024
github-actions[bot]
github-actions bot previously approved these changes Nov 28, 2024
github-actions[bot]
github-actions bot previously approved these changes Nov 29, 2024
github-actions[bot]
github-actions bot previously approved these changes Nov 29, 2024
@alecslupu alecslupu marked this pull request as ready for review November 29, 2024 06:31
@greenwoodt greenwoodt added module: proposals javascript Pull requests that update Javascript code labels Nov 29, 2024
@andreslucena andreslucena changed the title Optimize the proposals Optimize the proposals loading performance Nov 29, 2024
@andreslucena
Copy link
Copy Markdown
Member

Also I forget to add a little tiny detail in my review 😃

It works in my machine 🥳 🎉 !

This is what I'm doing for checking it out:

  1. Generate thousands of proposals in a single component, by opening a bin/rails console and running
require "decidim/seeds"
require "decidim/proposals/seeds"
component = Decidim::Component.find_by(manifest_name: "proposals")
900.times { Decidim::Proposals::Seeds.new(participatory_space: component.participatory_space).create_proposal!(component:) }
  1. Go to the proposals index page of that space
  2. In a terminal, run the following command:
tail -f development_app/log/* |grep "Completed"
  1. Load the page and copy the first request that appears

These are the numbers that I'm seeing:

A) On develop (without this patch):

Completed 200 OK in 7466ms (Views: 2981.8ms | ActiveRecord: 140.6ms | Allocations: 14484553)
Completed 200 OK in 7383ms (Views: 3021.6ms | ActiveRecord: 159.2ms | Allocations: 14526841)
Completed 200 OK in 7439ms (Views: 2837.1ms | ActiveRecord: 132.9ms | Allocations: 14478269)
Completed 200 OK in 7225ms (Views: 2848.0ms | ActiveRecord: 132.9ms | Allocations: 14468529)
Completed 200 OK in 7497ms (Views: 2854.4ms | ActiveRecord: 140.7ms | Allocations: 14375826)

B) On fix/proposals-author-cell (with this patch):

Completed 200 OK in 2017ms (Views: 1854.1ms | ActiveRecord: 111.6ms | Allocations: 4057078)
Completed 200 OK in 2059ms (Views: 1903.0ms | ActiveRecord: 102.1ms | Allocations: 4057081)
Completed 200 OK in 1961ms (Views: 1800.7ms | ActiveRecord: 110.0ms | Allocations: 4057073)
Completed 200 OK in 2062ms (Views: 1895.7ms | ActiveRecord: 113.8ms | Allocations: 4057009)
Completed 200 OK in 2021ms (Views: 1865.8ms | ActiveRecord: 102.4ms | Allocations: 4057070)

So, it seems like we're improving in almost every metric, most notably in the load times and the allocations numbers

@andreslucena
Copy link
Copy Markdown
Member

more details here: docs.google.com/document/d/1vR5ck119qNZ1ds6qniefxfgYVC0-voKOWoL-FcsLf9E/edit?usp=sharing

It asks for access, can you open the access? (if it doesn't have any PII of course)

@alecslupu
Copy link
Copy Markdown
Contributor Author

It asks for access, can you open the access? (if it doesn't have any PII of course)

check now . There is no private info in it (the stats are extracted from a seeded decidim instance).

Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>
github-actions[bot]
github-actions bot previously approved these changes Nov 29, 2024
github-actions[bot]
github-actions bot previously approved these changes Nov 29, 2024
github-actions[bot]
github-actions bot previously approved these changes Nov 29, 2024
@andreslucena
Copy link
Copy Markdown
Member

Development environment



Display in List mode before changes no cache


Display in Grid mode before changes no cache




Display in List mode before changes with cache


Display in Grid mode before changes with cache


Display in List mode after changes with cache

Display in Grid mode after changes with cache



Proposal view in Grid mode



  | Before optimization | After changes -- | -- | --   | no cache | cache | no cache | cache Time taken for tests | 815 | 529 | N/A | 216 Requests per second | 0.12 | 0.19 | N/A | 0.46 Time per request | 40757 | 26496 | N/A | 10839 Time per request ( MEAN) | 8151 | 5299 | N/A | 2167


@andreslucena andreslucena reopened this Dec 2, 2024
@andreslucena
Copy link
Copy Markdown
Member

andreslucena commented Dec 2, 2024

Sorry, I was trying to add the google docs content here but I pressed the wrong button. Just FYI @alecslupu: we don't do Google Docs for PRs, as it's using outside documents its a cancer for an Open Source project. Some time from now both of us could be out of the project and the new maintainers (or future researchers) may not have access because you removed, closed your google account or whatever other thing that may happen.

For this kind of contents it's much better to work it on a GitHub Gist and then copy and paste in the PR, so it's self-contained and we don't have future problems. Now we can leave it as is, because it's not worth actually redoing the whole document in GH markdown format and it's not a thing that can be copy and pasted (as HackMD or Notion that somewhat maintains the formatting).

(I added it, but the format is awful, and I don't want to waste time on fixing it)

@alecslupu
Copy link
Copy Markdown
Contributor Author

we don't do Google Docs for PRs, as it's using outside documents its a cancer for an Open Source project. ....

Attached the PDF version of the previously pasted docs (Yes, i know you already pasted them)
Decidim 0.29 - Proposal caching .pdf

@andreslucena
Copy link
Copy Markdown
Member

Can you merge with latest develop so we fix the failing spec? Thanks!

@alecslupu
Copy link
Copy Markdown
Contributor Author

@andreslucena We have a green pipeline

@andreslucena andreslucena merged commit 7e796c4 into develop Dec 9, 2024
@andreslucena andreslucena deleted the fix/proposals-author-cell branch December 9, 2024 14:14
@alecslupu alecslupu added the release: v0.29 Issues or PRs that need to be tackled for v0.29 label Dec 10, 2024
@github-actions github-actions bot added module: core module: design and removed javascript Pull requests that update Javascript code labels Dec 10, 2024
antopalidi pushed a commit that referenced this pull request Dec 16, 2024
* Optimize the proposals

* Fix failing specs

* Apply suggestions from code review

Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>

* Running linters

* Remove geocoded variable if the maps are not available

* Fix function description

* Codeclimate

---------

Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: core module: design module: proposals release: v0.29 Issues or PRs that need to be tackled for v0.29 type: fix PRs that implement a fix for a bug

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants