Famous / Famous/engine

Idea: Use transferable objects instead of constructing a new typed array in Buffer

Open
#431 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.7k
Forks
249
PR merge metrics
No merged PRs in 30d

Description

Sending an ArrayBuffer via `postMessage` and marking it as transferable might be worth investigating, since it would significantly lower the memory footprint due to
1. zero-copy transfer
2. no need to instantiate a typed array in `subData`

``` js
Buffer.prototype.subData = function subData() {
var gl = this.gl;
var data = [];

// to prevent against maximum call-stack issue.
for (var i = 0, chunk = 10000; i < this.data.length; i += chunk)
data = Array.prototype.concat.apply(data, this.data.slice(i, i + chunk));

this.buffer = this.buffer || gl.createBuffer();
gl.bindBuffer(this.target, this.buffer);
gl.bufferData(this.target, new this.type(data), gl.STATIC_DRAW);
};
```

Also

``` js
// to prevent against maximum call-stack issue.
for (var i = 0, chunk = 10000; i < this.data.length; i += chunk)
data = Array.prototype.concat.apply(data, this.data.slice(i, i + chunk));
```

should be removed IMO. It seems very excessive in terms of memory footprint and execution time.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.