svgdotjs / svg.js

The lightweight library for manipulating and animating SVG
https://svgjs.dev
Other
11.15k stars 1.08k forks source link

A way to deep delete shapes #1056

Closed acenturyandabit closed 4 years ago

acenturyandabit commented 4 years ago

Feature request: deep delete objects

Im a long time user of svgjs and am really appreciative of your effort. I know I can remove an element using remove(), but somehow it still takes up processing to edit items in the containing container after the element has been removed.

I use svg js as part of a dynamic UI with lots of zooming and rearranging, and although I try where I can to modify existing elements, sometimes I feel the need to remove old ones that are no longer used, especially in long sessions when things start to slow down.

Also perhaps a related request: I use paths + markers to make arrowed lines and it seems they take longer to update than to make from scratch. Can this be mitigated?

Benefits

I think the syntax to achieve this should be:

rect.destroy()
Fuzzyma commented 4 years ago

When you call remove, the element is removed from the dom. As long as you dont take a reference to the object or have an event listener bound to the object, it gets garbage collected and does not take up any space or "processing power". If you have problems with performance, profile your application. If you then find something which takes up too much time, go deeper into that.

Also perhaps a related request: I use paths + markers to make arrowed lines and it seems they take longer to update than to make from scratch. Can this be mitigated?

No not really. If you feel, that its faster to recreate it, do just that

acenturyandabit commented 4 years ago

Hey Fuzzyma, Thanks for getting back to me. I call remove() and I dont have any references except for let's in functions... I wonder if they count?

And yeah I do profile it and i get a bunch of time spent on update layer tree which is not function related :( I'm glad its not an svg js problem though.

saivan commented 4 years ago

let's in functions can count if they are hoisted. Yes this would be unlikely to be a problem with svgjs. But you can profile your app and look at the heap :) You'll be able to see the memory allocations and try to find the problem