colinmeinke / wilderness

An SVG animation API
https://wilderness.now.sh
MIT License
154 stars 8 forks source link

Reduce garbage collection frequency #71

Open colinmeinke opened 6 years ago

colinmeinke commented 6 years ago

How is Wilderness handling memory? FPS? What are the bottlenecks? What improvements can be made?

dalisoft commented 6 years ago

FPS works nice, but memory can be optimized via reducing objects count and prepare shape before starting tweeen

colinmeinke commented 6 years ago

Yes FPS seems okay on my macbook pro, but this simple example seems janky. It's potentially being garbage collected too regularly (9 times in 6 seconds?).

chrome timeline

dalisoft commented 6 years ago

Creating less objects, array slightly improves performance. Reusing arrays and objects, caching gives even better results

colinmeinke commented 6 years ago

I've made some good initial progress on reducing objects. Garbage collection frequency has halved in my tests.

There's still plenty more to do in core. One area specifically to improve is middleware. Currently every tweened value is output through every piece of enabled middleware. This is unnecessary. I will think of a better way to do this.

colinmeinke commented 6 years ago

Another area to refactor is the event system. Even if there are no event subscriptions Wilderness calls events function on each tick of a timeline. This creates a couple of new objects.

I'm thinking of changing the API here so that event subscription can only happen at timeline creation.

const timelineFinishCallback = () => alert('timeline finished')

const shapeStartCallback = shapeName => {
  if (shapeName === 'SHAPE_1') {
    alert('shape 1 started')
  }
}

timeline(shape1, shape2, {
  events: [
    [ 'timeline.finish', timelineFinishCallback ],
    [ 'shape.start', shapeStartCallback ]
  ]
})

This way for timelines with no events (I assume this will be the majority), there will be zero overhead from the event system.

dalisoft commented 6 years ago

The GSAP cannot be compared to this as this is free and available for anyone. That is matter for a lot of developers, newbies and others. Wilderness is free and enough fast to made smooth UI with morph. Maybe i wrong... Check out this https://www.npmjs.com/package/es6tween-plugin-morph maybe this is comparable because its free and based on points and svgpoints with some helpers. Also i build some morph that does from group to path or etc or vice versa. The es6tween morph plugin also not bad. Does group to group and path to any except group and so on.

dalisoft commented 6 years ago

About performance the last commits looks nice.