BuilderIO / partytown

Relocate resource intensive third-party scripts off of the main thread and into a web worker. 🎉
https://partytown.builder.io
MIT License
13.01k stars 432 forks source link

[🐞] High Total Blocking Time (TBT) using Google Analytics and partytown #513

Open benmccann opened 9 months ago

benmccann commented 9 months ago

Describe the bug

Screenshot from 2023-12-26 09-05-03

Screenshot from 2023-12-15 22-33-37

I don't know if this is purely unavoidable. However, it surprised me as I thought Partytown was supposed to move all computations off the main thread.

My page speed score is a couple of points better without Partytown + GA. However, Partytown + GA is still several points better than GA alone.

Reproduction

https://partytown.builder.io/google-tag-manager

Steps to reproduce

Setup Google Analytics with Partytown. E.g. I followed https://partytown.builder.io/sveltekit

Then use https://pagespeed.web.dev/ (look under "Avoid long main-thread tasks") or https://webpagetest.org/ to see that Partytown is significantly blocking the main thread.

Browser Info

Chrome

Additional Information

No response

benmccann commented 8 months ago

Looks like Lighthouse has gotten stricter on its scoring. That amount of blocking time is now taking 7 points of the Lighthouse score

Screenshot from 2024-01-09 08-09-52

gioboa commented 8 months ago

Can you try with the new release pls? Thanks

benmccann commented 8 months ago

Thank you for taking a look. Unfortunately no improvement

Screenshot from 2024-01-09 14-13-37

gioboa commented 8 months ago

Here is my result. This is your website, right?

Screenshot 2024-01-09 at 23 36 36
benmccann commented 8 months ago

Yes, that's my site that I've been testing with. The overall score is somewhat variable with some runs doing better than others. Obviously the site scores well overall, but I can't help but want to get to 100 :grin: Probably the most useful piece to look at rather than the overall score is the "Avoid long main-thread tasks" section and see whether Partytown is listed there as contributing to Total Blocking Time. My expectation was that Partytown shouldn't block, but I have limited insight into the internals, so perhaps there's some reason it's not possible for Partytown to operate in a non-blocking way.

stefan9541 commented 3 weeks ago

have the same issue, in my case overall TBT by partytown-sandbox-sw.htm same as I had with Google Analytics and google-tag-manager scripts together)