skevy / wobble

A tiny (~1.7 KB gzipped) spring physics micro-library that models a damped harmonic oscillator.
https://wobble-demos.now.sh
MIT License
842 stars 19 forks source link

Major garbage collection sweeps causing jank #9

Open JonDum opened 6 years ago

JonDum commented 6 years ago

I'm noticing pretty bad GC sweeps every few seconds using a dozen or so springs.

I think the majority of this is coming from the object/closure oriented way springs are updated via updateConfig.

  updateConfig(updatedConfig: PartialSpringConfig): this {

    this._advanceSpringToTime(Date.now());

    const baseConfig = {
      fromValue: this._currentValue,
      initialVelocity: this._currentVelocity
    };

    this._config = {
      ...this._config,
      ...baseConfig,
      ...updatedConfig
    };

    this._reset();

    return this;
  }

https://github.com/skevy/wobble/blob/develop/src/index.ts#L152-L175

For reference, this SO answer details pretty nicely all the things that are going to allocate memory in js

I haven't looked too closely at _advanceSpringToTime yet, but I don't see any major culprits at first glance.

I like the minimalism of wobble and I'd like to submit some PRs if you want to discuss alternative syntax here first to avoid the {}'s.

skevy commented 6 years ago

Hi @JonDum!. I would be happy to accept PRs. I don't have a lot of time to work on this right now myself, but I promise to be responsive with review!

As far as this issue and #8, I appreciate the bug reports and have no doubt that there are issues here.

I'll be on the lookout for PRs! :)