Skip to content

Memory leak calling map.setFeatureState() frequently [0.46-beta1] #6839

Closed

Description

@ryanbaumann

mapbox-gl-js version: 0.46.0-beta1

browser: Chrome v67.0

OS: Windows 10

GPU: Geforce GTX 660 with latest driver 398.11

Steps to Trigger Behavior

  1. Load the example in Chrome on a Windows 10 device using a Nvidia GPU (GTX GeForce 660 series with latest drivers).
  2. Move the mouse cursor repeatedly over features in the map using map.setFeatureState() on a vector tile source to change the hovered feature's style. Do not zoom or pan the map.
  3. Each map.setFeatureState() call, the browser memory allocation increases. If you call setFeatureState() enough before zooming to new tiles, the browser crashes.

Link to Demonstration

Expected Behavior

  • Memory is reclaimed / minimally expanded for each new call of map.setFeatureState

Actual Behavior

  • Memory increases proportionately for each map.setFeatureState() call triggered
  • Memory is mostly reclaimed when loading and rendering a new zoom level of tiles

cc/ @asheemmamoowala

Activity

  1. changed the title [-]Memory Lead calling map.setFeatureState() frequently [0.46-beta1][/-] [+]Memory leak calling map.setFeatureState() frequently [0.46-beta1][/+] on Jun 20, 2018
  2. ChrisLoer commented on Jun 20, 2018

    @ChrisLoer
    Contributor

    @ryanbaumann Looking at that performance profile, the thing that solidly trends up is "Nodes", which I think is DOM nodes -- makes me suspect the actual problem is all the popups getting created. Can you remove the popup part of the code to see if you can still reproduce the leak?

    I didn't have much luck reproducing on Chrome/Windows 10 running in VirtualBox, but I think it may just be so slow that I'm not patient enough to get the leak to show up...

  3. ryanbaumann commented on Jun 20, 2018

    @ryanbaumann
    ContributorAuthor

    @ChrisLoer I removed the DOM element creation on mousemove. I and am still able to re-created the issue.

    Updated example without popup DOM element - https://bl.ocks.org/ryanbaumann/733ba99c5ca1d9d15259081b395e4b00/dee9a8fa1fec66ab5bbfe856aaa6604b1e70831c

    Profile:

    Chrome file

    GIF of memory allocation in Windows 10 for Chrome :
    screen recording 2018-06-20 at 11 41 am

  4. ChrisLoer commented on Jun 20, 2018

    @ChrisLoer
    Contributor

    Yup, looks like the popups were probably a red herring -- with that removed, the chrome profile doesn't show the "nodes" growth, but definitely looks like the same problem. Unfortunately the profile doesn't show much else going on -- JS heap usage looks like it ranges from 67-103 MB, which isn't anywhere near the several gigabyte growth for the process as a whole.

    So... maybe something to do with re-uploading the the state-dependent paint vertex array to the GPU so frequently?

    cc @ansis

  5. ChrisLoer commented on Jun 20, 2018

    @ChrisLoer
    Contributor

    This looks like the problem to me -- we re-upload when the paint arrays change, but if there's an existing vertex buffer we don't destroy it first:

    upload(context: Context) {
    if (this.paintVertexArray && this.paintVertexArray.arrayBuffer) {
    this.paintVertexBuffer = context.createVertexBuffer(this.paintVertexArray, this.paintVertexAttributes, this.expression.isStateDependent);
    }
    }

    I think since these are supposed to be created as "dynamicDraw" buffers, so using updateData is more appropriate than destroying/recreating buffers. Updating the two upload()s in program_configuration to look more like:

            if (this.paintVertexArray && this.paintVertexArray.arrayBuffer) {
                if (this.paintVertexBuffer && this.paintVertexBuffer.buffer) {
                    this.paintVertexBuffer.updateData(this.paintVertexArray);
                } else {
                    this.paintVertexBuffer = context.createVertexBuffer(this.paintVertexArray, this.paintVertexAttributes, this.expression.isStateDependent);
                }
            }
    

    Seems to have fixed the problem, at least in @ryanbaumann's test case.

  6. ansis commented on Jun 22, 2018

    @ansis
    Contributor

    @ChrisLoer yep! That's definitely what we need. And I'd guess this could have a pretty large performance benefit as well.

  7. self-assigned this
    on Jun 22, 2018
  8. added this to the 0.47.0 milestone on Jun 25, 2018
  9. ChrisLoer commented on Jun 25, 2018

    @ChrisLoer
    Contributor

    Fixed in #6853.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions