[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] Typed Arrays & Strings



On Wed, Jun 30, 2010 at 08:58, <ry@tinyclouds.org> wrote:
I'm not married to my API (from which CommonJS Binary/F was derived)
but for my use case (servers) being able to read and write strings
from and to the buffer is important and quite sensitive to
performance. I would like to offer up a non-browser implementation to
Typed Arrays but I need a native API to deal with strings.

I completely support this.

Few weeks ago I was researching the same thing and  made a prototype but didn't come up with a formal proposal yet.
The goal of my prototype (running on Mozilla) was to see how much more efficient could binary loading get by being able to load XHR content directly with an insert(string data) method instead of going through the charCodeAt-loop kind of thing :

Demo : http://neonux.com/webgl/binaryloader.html

The interesting part being :


xhr.overrideMimeType("text/plain; charset=x-user-defined");
...

		var res = xhr.responseText;
		var len = parseInt(xhr.getResponseHeader("Content-Length"));
		var buf = new WebGLUnsignedByteArray(len);

		var parsingStartTime = Date.now();
		if (this.forceCharCodeAt || !buf.insert) {
			for (var i = 0; i < len; ++i)
				buf[i] = res.charCodeAt(i) & 0xFF;
		} else if (buf.insert) {
			buf.insert(res);

 
Result was obviously consistently faster and allows 2x faster loading of large meshes and other binary data.

Endianness issues can be resolved by inserting with right offsets and corresponding typed WebGL*Array on a same WebGLArrayBuffer.


Regards,