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

CPU overloading with piwik js library #12497

Closed
nemish opened this issue Jan 23, 2018 · 2 comments
Closed

CPU overloading with piwik js library #12497

nemish opened this issue Jan 23, 2018 · 2 comments
Labels
c: Performance For when we could improve the performance / speed of Matomo. not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.

Comments

@nemish
Copy link

nemish commented Jan 23, 2018

Hi! We are using piwik.js library in our project and we've found a cpu overloading. There are near 300 elements to check visibility on page and even when page is idle (no scroll, no other user interactions on page) every analytics tick loads cpu too much. And isNodeVisible function takes most of time. Looks like we could reduce DOM calls by storing state of already tracked elements. Here is a link on fork with possible changes. https://github.com/nemish/piwik/tree/cpu-performance-2.
Is there any workaround how to fix this stuff or other advise how to decrease cpu load?
Here is a screenshot which can explain current situation.
2018-01-19 17 13 09

@tsteur
Copy link
Member

tsteur commented Jan 23, 2018

@nemish seems like you have visible content tracking enabled. Can you maybe share a link to the page? How many content blocks do you have on your page approx?

By default, Matomo checks for newly visible nodes on scroll, and every 750ms where the every 750ms can be customized and set to eg every 0ms (won't do it anymore) as on "scroll" should actually do the job. Possibly we should change the default value there to 0ms.

Additionally, we could set a property that caches that a node has been visible at some point. I think a simple solution may be even just something like this:

diff --git a/js/piwik.js b/js/piwik.js
index c2adab6363..24b44d0a34 100644
--- a/js/piwik.js
+++ b/js/piwik.js
@@ -1,5 +1,5 @@
 /*!
- * Piwik - free/libre analytics platform
+ * Matomo - free/libre analytics platform
  *
  * JavaScript tracking client
  *
@@ -2671,9 +2671,13 @@ if (typeof window.Piwik !== 'object') {
             },
             isNodeVisible: function (node)
             {
+                if (node && 'hasBeenVisible' in node && node.hasBeenVisible) {
+                    return true;
+                }
                 var isItVisible  = isVisible(node);
                 var isInViewport = this.isOrWasNodeInViewport(node);
-                return isItVisible && isInViewport;
+                node.hasBeenVisible = isItVisible && isInViewport;
+                return node.hasBeenVisible;
             },
             buildInteractionRequestParams: function (interaction, name, piece, target)
             {

This way the cache will also be used when a plugin calls the function and the logic is a bit simpler compared to 3.x-dev...nemish:cpu-performance-2 which does the same?

@tsteur tsteur added this to the 3.4.0 milestone Jan 23, 2018
@tsteur tsteur added the c: Performance For when we could improve the performance / speed of Matomo. label Jan 23, 2018
@mattab mattab added the Waiting for user feedback Indicates the Matomo team is waiting for feedback from the author or other users. label Mar 19, 2018
@mattab
Copy link
Member

mattab commented Dec 10, 2023

Thanks for contributing to this issue. As it has been a few months since the last activity and we believe this is likely not an issue anymore, we will now close this. If that's not the case, please do feel free to either reopen this issue or open a new one. We will gladly take a look again!

@mattab mattab closed this as not planned Won't fix, can't repro, duplicate, stale Dec 10, 2023
@sgiehl sgiehl added not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. and removed Waiting for user feedback Indicates the Matomo team is waiting for feedback from the author or other users. labels Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Performance For when we could improve the performance / speed of Matomo. not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

No branches or pull requests

4 participants