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

Posthog Script causing the UI components to load slow. #11194

Closed
1 task
abhisanson opened this issue Aug 9, 2022 · 26 comments
Closed
1 task

Posthog Script causing the UI components to load slow. #11194

abhisanson opened this issue Aug 9, 2022 · 26 comments
Labels
bug Something isn't working right performance Has to do with performance. For PRs, runs the clickhouse query performance suite

Comments

@abhisanson
Copy link

Bug description

Wanted to report an issue after the last upgrade we did to the posthog. Our users started to report slowness in loading of our app modals(which are in Angular) After investigation we found out the posthog script is interfering with the load times. we turned off the script and suddenly the issue was gone. Can you please advise. I am happy to share the before after screen recordings
Please describe.
If this affects the front-end, screenshots would be of great help.

How to reproduce

1.Script added to index.html
2. when loading certain pages the script blocks UI components loading
3.

Environment

  • self-hosted PostHog, v1.37.1

Additional context

With.posthog.mov
After.Removing.Posthog.mp4

Thank you for your bug report – we love squashing them!

@abhisanson abhisanson added the bug Something isn't working right label Aug 9, 2022
@pauldambra pauldambra added the performance Has to do with performance. For PRs, runs the clickhouse query performance suite label Aug 9, 2022
@pauldambra
Copy link
Member

Hey @abhisanson thanks for your report!

Do you see any console errors or failing network calls when PostHog is present?

Are you able to record and export a performance profile with and without PostHog to share with us? (We can share separately to GitHub if you're worried about what that might expose)

@abhisanson
Copy link
Author

@pauldambra there was an issue . We did an npm i to update the packages and it seems there is a dependency thats not letting us compile the code. We commented Posthog again and it works but the moment we add the code its give the error (see screenshot)
Screen Shot 2022-08-13 at 11 33 45 PM

@pauldambra
Copy link
Member

Ah, thanks @abhisanson! Can you confirm what version of posthog-js you're using?

@benjackwhite is this related to the recent Typescript changes?

@benjackwhite
Copy link
Contributor

Could be. Perhaps @mariusandra would have some ideas here

@pauldambra
Copy link
Member

Looking in posthog-js we have rrweb as a dev dependency and rrweb-snapshot as a dependency

@pauldambra
Copy link
Member

@abhisanson I made an index.js that imports and uses posthog-js and then used webpack to bundle it and didn't get any errors. Which might only mean I don't know how to recreate your error :)

I don't want to add dependencies and then discover it didn't fix anything for you :)

Where do you get the error pasted above? In your IDE, only on build, something else?

@abhisanson
Copy link
Author

@pauldambra it was on visual studio code also from terminal. When I try to start our frontend node server it occurs. See attached . It used to work just fine before the upgrade

Screen.Recording.2022-08-16.at.7.56.59.PM.mov

.

@abhisanson
Copy link
Author

@pauldambra the posthog JS version i have posthog-js@1.29.0

@abhisanson
Copy link
Author

@pauldambra any update?

@pauldambra
Copy link
Member

@benjackwhite @mariusandra do we need to add those dependencies more explicitly?

@abhisanson
Copy link
Author

@pauldambra @benjackwhite @mariusandra any update. One of our environments is running Posthog.js@1.21.0 and it compiles fine, but we do have the issue of slow loading.
Please advise..

thanks

@abhisanson
Copy link
Author

@pauldambra would really appreciate some help here. We have paused our scripts in prod and are loosing lot of customer recordings

@mariusandra
Copy link
Collaborator

I've pushed out a fix that will hopefully let you import the library without issues: PostHog/posthog-js#441

@abhisanson
Copy link
Author

abhisanson commented Aug 25, 2022

@mariusandra Thanks that helped . However we still have the same issue @pauldambra I have performance recordings with and without posthog. Please let me know where can share those?

@pauldambra
Copy link
Member

pauldambra commented Aug 26, 2022

Are you able to join our [community slack](https://posthog com/slack)?

@abhisanson
Copy link
Author

@pauldambra Yes I am on it. sent you a direct message there

@pauldambra
Copy link
Member

Adding comment from slack here


The difference in time spent is all in recorder.js. It looks like a conflict in a polyfill (although these performance graphs are really hard to read 🙂

My guess is that if you turn off session recording the performance impact will disappear. Although that’s not a long-term fix 😊

Do you know which version you upgraded from so I can see what might have changed?

I’ve seen Angular apps be very aggressive with changing the DOM and our screen recorder reacts to DOM changes. So my next bit of intuition would be to experiment there. Maybe try adding ph-no-capture to the timeline or other parts of the page. That would let us see whether a particular component on the page is causing the issue.

Are you able to test those two routes?

  1. is the performance impact still present without recording
  2. can we determine if specific components cause the slowdown by excluding them with ph-no-capture

@abhisanson
Copy link
Author

@pauldambra thats correct, confirming if I turned off recording from the dashboard, the performance issue disappears. Yes, we need those recordings :)

we upgraded from 1.33 to 1.37.1 6 -7 weeks back.

trying code changes to test with ph-no-capture. Will post the results shortly.

@pauldambra
Copy link
Member

cc @rcmarron

We've not tracked down the source of the performance impact from recordings here. But thought I'd tag you in case there are changes since 1.37.1 you think might affect things

@rcmarron
Copy link
Contributor

rcmarron commented Sep 1, 2022

Thanks @pauldambra, any impact from recordings would be related to posthog-js versions, and nothing substantial has changed there since the last rr-web upgrade in the spring.

@abhisanson Is there an environment or account that I could use that shows the performance issue? (if it's easier you can DM me in the PostHog user slack - I'm @rick marron). I've seen a few customers hit similar issues before in Angular apps, and in the past, it had been a loop that's constantly re-rendering a component, and as a result the MutationObserver is constantly firing massive events. Taking a look at what's firing from the mutation observer would be the first thing I check here.

@rick
Copy link

rick commented Sep 1, 2022

it me

@abhisanson
Copy link
Author

@rcmarron Thanks , I will enable PHog in my test environment and send you on slack.

@abhisanson
Copy link
Author

@rcmarron I have shared the login details with you on slack. please let me know if you able to access

@rustho
Copy link

rustho commented Sep 8, 2022

We have a very similar case on the project. We have a table that has lazy loading every 25 elements. As soon as these elements are rendered, the entire application dies until render not finish

@pauldambra
Copy link
Member

Hey @rustho 👋

The incomparable @rcmarron discovered that in this case the site in question had a polyfill for older browsers. Recording relies on mutation observer and the polyfill version was way slower.

If you don't think that's the issue here it's probably best to log a separate issue with as much as you can share publicly. If you can't share publicly feel free to join our community slack posthog.com/slack

We have a different support hero each week and you can DM them in the slack with private info

@pauldambra
Copy link
Member

@abhisanson I'm going to close this issue since we've discovered the source. Please feel free to keep the conversation going in the community slack 💖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right performance Has to do with performance. For PRs, runs the clickhouse query performance suite
Projects
None yet
Development

No branches or pull requests

7 participants