-
Notifications
You must be signed in to change notification settings - Fork 86
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
Memory leaks with continue updated input data #270
Comments
In order to free resources when they are not needed anymore, you need to call <!DOCTYPE html>
<head>
<meta charset="utf-8" />
<script src="https://cdn.jsdelivr.net/npm/vega@5"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@4.0.0-beta.2"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@5"></script>
</head>
<body>
<div id="vis"></div>
<script>
const spec1 = {
$schema: "https://vega.github.io/schema/vega-lite/v4.json",
width: 360,
data: {
values: [
{ a: "A", b: 28 },
{ a: "B", b: 55 },
{ a: "C", b: 43 },
{ a: "D", b: 91 },
{ a: "E", b: 81 },
{ a: "F", b: 53 },
{ a: "G", b: 19 },
{ a: "H", b: 87 },
{ a: "I", b: 52 }
]
},
mark: "bar",
encoding: {
x: { field: "a", type: "ordinal" },
y: { field: "b", type: "quantitative" },
tooltip: { field: "b", type: "quantitative" }
}
};
const spec2 = {
$schema: "https://vega.github.io/schema/vega-lite/v4.json",
description: "A simple bar chart with embedded data.",
width: 500,
data: {
values: [
{ a: "A", b: 33 },
{ a: "B", b: 32 },
{ a: "C", b: 16 },
{ a: "D", b: 28 },
{ a: "E", b: 35 },
{ a: "F", b: 81 },
{ a: "G", b: 90 },
{ a: "H", b: 10 },
{ a: "I", b: 5 }
]
},
mark: "bar",
encoding: {
x: { field: "a", type: "ordinal" },
y: { field: "b", type: "quantitative" },
tooltip: { field: "b", type: "quantitative" }
}
};
let spec = spec1;
let view;
function myFunction() {
setInterval(function() {
if (spec === spec1) spec = spec2;
else spec = spec1;
if (view) {
view.finalize();
}
vegaEmbed("#vis", spec)
.then(function(result) {
// save view so we can finalize it
view = result.view;
})
.catch(console.warn);
}, 1000);
}
</script>
<button onclick="myFunction()">Update</button>
</body> Try it at https://blockbuilder.org/domoritz/cfdc1c68553a7b942ad3055a63995dd3. |
The cleaner (and faster) solution is to use the view API instead. I'll leave this as an exercise for the reader ;-) |
Thanks. How I get it done with react-vega? |
I tried the updated code. But the memory is still increasing. |
How are you tracking memory usage? can you use the browser memory debugger? It should also show who is holding on to memory. |
I only open one tab in chrome, that runs the example above. Do not do anything else with the chrome. Keep looking at the process named "Google Chrome Helper (GPU)". It is found that it keeps increasing, from hundreds MB to several GBs. |
Can you find out what's holding on to the memory? |
I debug the problem with Chrome Task Manager. I found the memory used by the tab keep increasing slowly. But the task named "GPU Process" keeps increasing markedly. |
Thanks. |
Do you find why the memory leaks happen? |
No, I didn't have time to look yet. |
Is there someone still take care of this problem? I believe it is an important problem for practical usage of vega-embed and related vega, vega-lite. I would like to help. Would anyone give some tip for how to debug and challenge this problem? Thanks. |
I've been swamped with other requests but completely agree that this is an important issue to look into. What I'm curious about is what objects are holding onto memory that may not need to. I'd use the browser memory debugger to do that. |
Fixed in #280 |
Great. Looking forward to the next release. |
I believe the problem appear again. The screenshot below show the memory profile of the example above.
|
Please finalize the embed result as described in the docs. |
We use react-vega, which calls finalize as follows. Is there something we should do more? Thanks.
|
I don't know how this fits into the react lifecycle. However, your example above does not contain finalize. Can you add finalize to see whether it fixes the issue? If yes, then we know the problem is in react vega. Thanks for your help! |
I tried to call finalize as follows. And the memory cost show as the screenshot image.
|
That’s good, right? |
Yes. I proposed an issue for react-vega. |
We're having what I think may be the same problem too; the difference for us is that we aren't using Since we aren't creating a new Unfortunately I don't have a clean minimal-reproduction example. |
Can you try to reproduce the issue with a small example and file an issue with Vega directly? |
Is there any plan to update react-vega to fix the problem? Or else is there any way to use vega-embed with react directly? |
@domoritz I can file with Vega directly, but I'm not sure I have time to narrow it down to a small example. I'll see what I can do. |
That's easily possible with a reference. Something like this:
You may also be interested in vega/vega#2652 |
Is the memory leak caused by the Vega caches? |
Memory leaks could arise from multiple sources:
PR vega/vega#2652 should fix number 2 above. Number 1 needs to be addressed by developer code (or in libraries such as vega-embed or vega-react). |
The memory leaks still happen while react-vega calls finalize. Is it caused by number 2 above? |
These is memory leaks with vega-embed. For example, with following example, by clicking button update. The memory used keeps increasing. Is there any way to solve it? Thanks.
The text was updated successfully, but these errors were encountered: