Memory footprint

First attempt. Starting from a 473 empty BloP footprint and a 2554 footprint after loading 80 custom blocks, I tried not to create canvases for all morphs in Morph.prototype.DrawNew. There is a slight improvement, but I guess I'm missing something important.

  • avoiding to draw CustomCommandBlockMorphs && CustomReporterBlockMorphs: 2518
  • avoiding to draw Morphs that have got a parentThatIsA(CustomCommandBlockMorph) || parentThatIsA(CustomReporterBlockMorph) too: 2456
    Any suggestion is welcome.

Going back to freeing memory by using the garbage collector, I don't understand why setting world.children[0].stage (that is the Stage) to null or deleting it before opening a new project does not solve the problem. As far as I understand, the stage is what has almost every other element of Snap "under" it. So, deleting it, should make the most part of javascript memory available.

Should I free the stage recursively? Or are there in Snap other references to the Stage that don't make it really available after deletion?

in newer web browser generations it's kinda unpredictable whether canvas data will end up in RAM or in the GPU's memory, and - to make things worse - that may change several times during a canvas element's life cycle.

I just realized that there is no link from the custom block I can reach by following the path definition.body.expression of a CustomCommandBlockMorph and the CustomCommandBlockMorph. Indeed the parent attribute is null.

How can I understand if a morph I'm creating is inside a CustomCommandBlockMorph/CustomReporterBlockMorph?

there is no back link. You might have to catch it before. I've been thinking of replacing all accessors to Morph.prototype.image with and ad-hoc rendering method that caches the result for some Morphs but not for others. These are deep architectural changes, I'm afraid...

Thanks. A quick question: are all the blocks of the definition script of a custom block reachable from the "expression" attribute?

only the function body expression itself. Other scripts and blocks can be in scripts

Do you mean scripts and blocks not attached to the prototype hat?

yes, exactly.