Skip to content

Bug: PostHog consuming excessive browser memoryΒ #32479

Closed

Description

@luke-belton

Bug Description

Bug description

There have been a couple of reports so far from users that the PostHog app has been consuming excessive browser memory.

How to reproduce

No concrete reproduction steps yet.

However one user reported that the memory accumulates while tabs are in the background, and the memory quickly reduces when reopening the tab.

It hasn't been linked to any specific browser extensions. Currently unclear if this is reproducible in incognito/private browser windows.

Additional context

From:

Debug info

null

Activity

  1. added
    bug
    on May 21, 2025
  2. pauldambra commented on Jun 3, 2025

    @pauldambra
    Member

    i managed to catch a tab using obviously too much RAM and all on the heap

    in that case at least I believe this was the fix #32979

    🀞that's the only case

  3. luke-belton commented on Aug 5, 2025

    @luke-belton
    ContributorAuthor
  4. luke-belton commented on Sep 8, 2025

    @luke-belton
    ContributorAuthor
  5. luke-belton commented on Sep 9, 2025

    @luke-belton
    ContributorAuthor
  6. pauldambra commented on Sep 18, 2025

    @pauldambra
    Member

    long text incoming

    i've added RAM monitoring to the app and you can view the insight here

    That also tracks if the window was focussed or visible and if session recording was active at the time of capture

    That shows that roughly

    • this is generally worse when in the background or out of focus
    • this is always worse when replay is running

    some hand-waving here because this is only exposed to us in chrome, and i believe it is only measuring the heap

    i have seen Chrome visually report very high RAM usage and there not be much memory on the heap. so this replay finding could be a red herring or only one of several overlapping problems

    i've also seen the django site admin using excessive ram, that is after a full navigation, and never has replay running. but that could be a red herring or a different problem too


    replay could be causing the problem from playback behaviour or from recording behaviour
    but since this graph seems to show us using less RAM when recording is not active then we will assume it is a recording behaviour until we know otherwise (although we don't get general reports of this from customers so it isn't whenever any recording is running)

    showing median and max reported memory usage

    state with recording without recording
    visible, focussed max and median ram, visible, focussed, recording max and median ram, visible, focussed, not recording
    visible, not focussed max and median ram, visible, not focussed, with recording max and median ram, visible, not focussed, without recording
    not visible, not focussed Image Image

    i don't think this is the whole story but it's certainly worth investigating

  7. pauldambra commented on Sep 18, 2025

    @pauldambra
    Member

    we can do a little naive grouping by RAM

    SELECT host, pathname_masked, max(RAM) AS max_ram
    FROM (
        SELECT 
            properties.$host AS host, 
            replaceRegexpAll(
                replaceRegexpAll(
                    replaceRegexpAll(
                        properties.$pathname, 
                        '/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}', '/*'
                    ),
                    '/[0-9]+', '/*'
                ),
                '/[A-Za-z0-9]{10,}', '/*'
            ) AS pathname_masked,
            properties.usedJSHeapSize / 1024 / 1024 AS RAM
        FROM events
        WHERE event = 'memory_usage'
          AND timestamp >= now() - INTERVAL 7 DAY
          AND properties.usedJSHeapSize / 1024 / 1024 > 700
    )
    GROUP BY host, pathname_masked
    ORDER BY max_ram DESC
    
    Image

    or a similar query just counting number of sessions by path > 700MB RAM

    Image
  8. pauldambra commented on Sep 18, 2025

    @pauldambra
    Member

    NB replay page is always going to show high max memory usage because we load recordings data into memory in order to play them which will either mislead us or mask a real problem

  9. luke-belton commented on Sep 22, 2025

    @luke-belton
    ContributorAuthor

    @pauldambra - not sure if this is helpful, but for interest I ran your query for person_id = 'b742f0d5-454c-5f0a-8a08-25d9bdc96598' over the last 90d (one of the users that raised this with us). This doesn't return any results - so seems like either we haven't captured an event while they've been in a bad state (they have plenty of memory_usage events though), or there's another explanation like we're not measuring the actual memory problem (e.g. your comment about this property accounting for heap memory only)?

  10. pauldambra commented on Sep 22, 2025

    @pauldambra
    Member

    yep @luke-belton there's very limited visibility for us here
    i wanted to capture heap memory since it's available and it can't hurt

    i've a few theories but nothing concrete 🫠

  11. pauldambra commented on Sep 22, 2025

    @pauldambra
    Member

    #38466 (total fly-by why not poke with a stick)

  12. pauldambra commented on Sep 23, 2025

    @pauldambra
    Member

    user here has agreed to block posthog's recorder asset

    https://posthoghelp.zendesk.com/agent/tickets/37172 (moved to PostHog: https://us.posthog.com/project/2/support/tickets/41559)

    before this they can reliably reproduce this issue... now we wait to see if this resolves it for them... at least to narrow down the cause

  13. pauldambra commented on Sep 24, 2025

    @pauldambra
    Member

    2 different users have tested blocking the posthog/rrweb recorder and it hasn't resolved things, that's sort of good news since that would have been the hardest to fix...

    Next thing to investigate is whether we're accruing detached DOM nodes in a bunch of places

  14. luke-belton commented on Sep 24, 2025

    @luke-belton
    ContributorAuthor
  15. pauldambra commented on Sep 24, 2025

    @pauldambra
    Member

    ok, next angle is whether we are slowly leaking detached DOM nodes

    #38572

    this PR will turn off replay preview during timeline hover (so (sort of) one fewer player on the page) and improves cleanup a little bit

    in my very unscientific testing it helps, but then i don't know i'm really measuring the right thing


    on that note though, this is a replay change. and i had a tab that visited the home page, then the toolbar launch page, then sat idle all night and chrome reported it was using a tonne of RAM. so this won't be a replay only fix

  16. 62 remaining items

  17. pauldambra commented on Jul 6, 2026

    @pauldambra
    Member

    ok, we finally found https://issues.chromium.org/issues/351244335

    i reorganised how the posthog app and the posthog web SDK deal with local storage and this is hugely improved

    i have seen some very long lived tabs in the background hit ~1GB but I think the app improvements and the attempt to sidestep this chromium bug have effectively fixed this

    my proposal is we can close this issue since i think it no longer has user facing effect

  18. self-assigned this
    on Jul 6, 2026
  19. pauldambra commented on Jul 19, 2026

    @pauldambra
    Member

    we're no longer getting reports of this

    the main fix here was massively reducing how often we write to local storage and how much we write to local storage to avoid triggering the chromium bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions