Skip to content

Object.defineProperty in THREE.Vector3 constructor causing a significant performance penalty  #21284

@pjanik

Description

@pjanik

Describe the bug

I've noticed a significant performance drop in my application when I upgraded the THREE.JS version. Initially from 0.102.0 to 0.125.2, but I've narrowed it down to a change from 0.119.1 to 0.120.0. A single model step in my app (simulation) increased from ~10ms to ~50ms.

I've used JS profiler and noticed that Vector3.clone() is at the top now:
Screenshot 2021-02-15 at 18 34 12

I'm using THREE.Vector3 in the simulation part of the app, and since many vector operations are implemented in place, .clone() calls are very common. When I downgrade version to 0.119.1, the clone operation isn't there anymore and the model step calculates 4 times faster.

I did a little investigation and replacing Object.defineProperty( this, 'isVector3', { value: true } ); in THREE.Vector3 constructor with this.isVector3 = true; fixes the issue.

To Reproduce, Live example

On my machine, the difference is 5ms (r119) vs 45ms (r120, r125).

I don't think it'd be useful here, but the app I'm working on:
https://tectonic-explorer.concord.org/?preset=subduction

Expected behavior

No .clone performance drop.

Screenshots

THREE.JS version 0.119.1 vs 0.120.0:

Screenshot 2021-02-15 at 18 33 25

Platform:

  • Device: Desktop
  • OS: MacOS
  • Browser: Chrome v88
  • Three.js version: r120.0 and newer, r119 is the last one that works fine

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions