From 1b4199ccd01fd8218d19bba19aa1224e50cdceab Mon Sep 17 00:00:00 2001 From: Aliaksey Kandratsenka Date: Mon, 11 Oct 2010 14:35:25 -0700 Subject: [PATCH] [flot] returned canvas reuse This gives us _massive_ improvement in memory use. Before that Chrome could easily grab as much as 400M for heap, with this patch it seems to stay way below 100M. This basically reverts 6fe0258642cf1c465be3a9b5bee1005cd46a2d59 back. Which applied flot patch from here: http://code.google.com/p/flot/issues/detail?id=269 Change-Id: Icf9bd8d828c1c36e4fdd0886bca44407148ef2b7 Reviewed-on: http://review.membase.org/3319 Reviewed-by: Aliaksey Kandratsenka Tested-by: Aliaksey Kandratsenka Reviewed-by: Steve Yen --- deps/menelaus/priv/js/jquery.flot.js | 30 +++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/deps/menelaus/priv/js/jquery.flot.js b/deps/menelaus/priv/js/jquery.flot.js index 03136b561f..b5b62e3918 100644 --- a/deps/menelaus/priv/js/jquery.flot.js +++ b/deps/menelaus/priv/js/jquery.flot.js @@ -540,10 +540,26 @@ c = window.G_vmlCanvasManager.initElement(c); return c; } - + canvasWidth = placeholder.width(); canvasHeight = placeholder.height(); - placeholder.html(""); // clear placeholder + var checkCanvas = placeholder.children('canvas'); + if (checkCanvas.length && + (checkCanvas.get(0).width == canvasWidth) && + (checkCanvas.get(0).height == canvasHeight)){ + canvas = checkCanvas.get(0); + ctx = canvas.getContext('2d'); + overlay = checkCanvas.get(1); + octx = overlay.getContext('2d'); + + //do whatever manual clearing is necessary here + ctx.clearRect(0,0,canvasWidth,canvasHeight); + octx.clearRect(0,0,canvasWidth,canvasHeight); + unbindEvents(); + } else { + placeholder.get(0).innerHTML = ''; //this helps with leaky memory possibly + //placeholder.html(""); // clear placeholder + if (placeholder.css("position") == 'static') placeholder.css("position", "relative"); // for positioning labels and overlay @@ -552,7 +568,7 @@ if ($.browser.msie) // excanvas hack window.G_vmlCanvasManager.init_(document); // make sure everything is setup - + // the canvas canvas = $(makeCanvas(canvasWidth, canvasHeight)).appendTo(placeholder).get(0); ctx = canvas.getContext("2d"); @@ -561,6 +577,7 @@ overlay = $(makeCanvas(canvasWidth, canvasHeight)).css({ position: 'absolute', left: 0, top: 0 }).appendTo(placeholder).get(0); octx = overlay.getContext("2d"); octx.stroke(); + } } function bindEvents() { @@ -578,6 +595,13 @@ executeHooks(hooks.bindEvents, [eventHolder]); } + function unbindEvents() { + // we include the canvas in the event holder too, because IE 7 + // sometimes has trouble with the stacking order + eventHolder = $([overlay, canvas]); + eventHolder.unbind(); + } + function setupGrid() { function setTransformationHelpers(axis, o) { function identity(x) { return x; }