Idea: Use transferable objects instead of constructing a new typed array in Buffer
- 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
Assessment
This issue has not been assessed yet.