-
Notifications
You must be signed in to change notification settings - Fork 53
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
Javascript version #13
Comments
Yes, this looks possible now. |
The Emscripten compilation of this lib also look promising, but I don't know what a dynamic call from javascript would look like. Emscripten generates a lot of constants and heap allocations. |
I am somewhat pessimistic regarding any approach that does not translate into SIMD instructions at the machine level. |
Please note that SIMD is currently in the crosswalk V8 fork: |
Hmm perhaps you are right, nevermind. I can't find it in the repo. |
Continuing from #10, the performance of the first example compiled to javascript with Emscripten performs well, but performance of other 2 tests is extremely poor. It seems SIMD.js is nowhere near being compatible with this project. |
Can you tell us which examples fare well and which ones fare badly? |
When I compiled previously with my smmintrin shim the first two test would run, but simple_demo would hang, currently the second example didn't finish in any acceptable time, only the first compress_decompress example finishes in ff nightly. |
What happens after this last commit b7e1ecc ? |
@lemire yes, that script does finish, in about 8 seconds in FF nightly on my i7-3612QM (8GB). |
Ok. Can you share the resulting output (just so we can document it). |
@lemire sorry, I did, but I replied to the commit. Here goes: |
Thanks, but I am inviting you to publish the performance results you got. My concern right now is whether SIMD instructions are used at all. On my laptop, the script completes, but very slowly and with speeds that indicate that SIMD instructions are not used. |
_compress_decompress_demo: 10-50 ms |
@wshager Do you have the screen output where it compares the memcpy speed with the decoding speed? On my Firefox, things just freeze, so it is no use. On Google Chrome, I do not even get 1 million int. per second. |
Ah sorry I misunderstood. Here it is: == simple test gap = 1 gap = 3 gap = 9 gap = 27 gap = 81 gap = 243 |
@lemire did you install nightly? https://nightly.mozilla.org |
These results are better than what I get with Google Chrome but still not close to what one would want. These results are thousands of times slower than C. That's not surprising given that it is JavaScript... but still... |
@lemire agreed, too bad. Perhaps the generated js isn't optimal. |
@wshager Yes, manual inspection of the generated code might be telling. |
@lemire the abstractions in SIMD.js may be clearer, but the downside is that there's no way to convert the code back to pure functions... unless I take on the quixotic task of rewriting SIMD.js to pure functions. |
Currently the function mapping is as follows: Anyway, the generated code is quite unreadable, because each transformation is assigned to a variable (which may also impede performance). |
No matter. I think it is useful and important to experiment, even when the results are underwhelming. |
I've created an interface from (client-side) javascript to the simdcomp library using Emscripten. What I fail to understand is how to decompress a Uint8Array. var maxbits_length = Module.cwrap('maxbits_length', 'number', ['number','number']);
var simdpack_length = Module.cwrap('simdpack_length', 'number', ['number','number','number','number']);
var simdunpack_length = Module.cwrap('simdunpack_length', 'number', ['number','number','number','number']);
var n = 128;
var data = new Uint32Array(128);
for (var k = 0; k < n; k++){
data[k] = k+3;
}
//var n = data.length;
// Get data byte size, allocate memory on Emscripten heap, and get pointer
var nDataBytes = n * data.BYTES_PER_ELEMENT;
var dataPtr = Module._malloc(nDataBytes);
// Copy data to Emscripten heap
var dataHeap = new Uint8Array(Module.HEAPU8.buffer, dataPtr, nDataBytes);
dataHeap.set( new Uint8Array(data.buffer) );
// Call the function by passing a number pointing to the byte location of
// the array of pointers on the Emscripten heap. Emscripten knows what to do!
var b = maxbits_length(dataHeap.byteOffset, n);
var nOutBytes = nDataBytes + n / 128;
var outPtr = Module._malloc(nOutBytes);
simdpack_length(dataHeap.byteOffset, n ,outPtr,b);
var outHeap = new Uint8Array(Module.HEAPU8.buffer, outPtr, nOutBytes);
//var out = new Uint8Array(outHeap.buffer, outHeap.byteOffset, n + n);
var backPtr = Module._malloc(nDataBytes);
simdunpack_length(outHeap.byteOffset, n , backPtr, b);
var backHeap = new Uint8Array(Module.HEAPU8.buffer, backPtr, nDataBytes);
var back = new Uint32Array(backHeap.buffer, backHeap.byteOffset, n);
console.log(back);
// Free memory
Module._free(dataHeap.byteOffset);
Module._free(outHeap.byteOffset);
Module._free(backHeap.byteOffset); |
@wshager I am not very familiar with Emscripten. Do you know how to achieve what you are trying to achieve in C? If you do then, presumably, it is simply a matter of translating the appropriate C code. |
@lemire following the updated example code, the serialized compressed array now successfully decompresses. What I was wondering is that in client-side javascript, providing a license is somewhat complicated, as the code is |
This C code falls under the BSD License. If you want to repackage it as JavaScript and redistribute it, you can use BSD as well. |
Though it is not a port of this library per se, the following JavaScript library might be of interest... |
@lemire great! I'll check it out, it will no doubt be very useful until we have full SIMD support. |
3 years later and all of the examples return "speed in million of integers per second 0.184491" or less in Chrome on my system! I added the following code inside the
|
It would be interesting to see if a javascript version of this library could be created using SIMD.js.
https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Global_Objects/SIMD
https://github.com/tc39/ecmascript_simd
https://github.com/jonbrennecke/node-simd
The text was updated successfully, but these errors were encountered: