Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constantly re-allocating array is much slower than appending #15

Open
nikitakit opened this issue Oct 27, 2016 · 0 comments
Open

Constantly re-allocating array is much slower than appending #15

nikitakit opened this issue Oct 27, 2016 · 0 comments

Comments

@nikitakit
Copy link

The code at mesh-plugin.js:101 currently reads:

      // accumulate mesh vertices and uv
      var model = this.meshCustomBlock(value,x,y,z);
      vertices = vertices.concat(model.vertices);
      uv = uv.concat(model.uv);

The use of concat causes the allocation of new arrays (of ever increasing size), which is needlessly expensive. Appending in-place is much faster, e.g.

      var model = this.meshCustomBlock(value,x,y,z);
      for (var j = 0; j < model.vertices.length; j++) {
          vertices.push(model.vertices[j]);
      }
      for (var k = 0; k < model.uv.length; k++) {
          uv.push(model.uv[k]);
      }

I'm rendering some maps using a chunk distance of 2-4, 32x32x32 chunks, and using custom block models for a significant fraction of the blocks in the scene. This change significantly improves performance for my application (reducing meshing time by as much as 10 seconds!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant