bonfire-networks / bonfire-app

Bonfire - tend to your digital life in community. Customise and host your own online space and control your experience at the most granular level.
https://bonfirenetworks.org
GNU Affero General Public License v3.0
596 stars 45 forks source link

Debugging performance with Phoenix LiveDashboard #891

Open ivanminutillo opened 9 months ago

ivanminutillo commented 9 months ago

Following some interesting insights about potential performance issues found using LiveDashboard tools, esp. Orion and Flame on. The functions are recorded during the loading of the Home feed

Bonfire.Common.Extend.maybe_extension_loaded!/1 Execution is pretty fast (99% under 9ms), but (If I understand the graph correctly) it is been called in a range of 160 - 260 times x second across a period of 55 secs (15:21:10 - 15:22:05)

Performance Graph: image Profiler: image zooming out :

Screenshot 2024-03-02 alle 15 41 47

My guess is that even if the time execution is very fast, the amount of time the function is called for such a consistent period of time may cause the instance to consistently slow down? Looking at the profiler graph, in first instance I tought that impressive repetition that is shown in the flame graph was caused by a recursive loop somewhere, but maybe it's just a consequence of how modular is bonfire and how modules from different extensions are linked together in a complex view such as the Feed view.

I'm not that good with the BEAM to say tough if this can likely be an issue or not? Feedback are very welcome :)

mayel commented 9 months ago

Just had a quick look, maybe_extension_loaded! is called whenever you do Config.get or Settings.get so the amount of times isn't necessarily alarming, though always good to double check, and probably the functions can be reduced/optimised a bit when we know how often they're used...

ivanminutillo commented 9 months ago

yeah maybe for foundational extensions (such as ui_social / ui_reactions / boundaries / etc) we can assume they're enabled? or we can cache the list of extensions loaded? because they are not likely to change that often and they are updated only via settings so updating the cache should be trivial enough?

mayel commented 9 months ago

we can assume they're enabled

I'd not do that, would loose flexibility and the ability to swap them out

we can cache the list of extensions loaded

seems to assume that elixir/erlang is not already caching or that they're slow, which we just need to measure

ivanminutillo commented 9 months ago

Adding the list of potential N+1 (from logs and honeycomb)

mayel commented 8 months ago

added some extra measuring of memory use and execution time during runtime...