-
Notifications
You must be signed in to change notification settings - Fork 1.2k
bignumber.js vs long.js #2118
Comments
I would recommend a WASM implementation instead. |
Exactly! This could be a great way to test out assemblyscript. Or if you find it too time consuming a rustwasm solution. Ping if you need help. |
@mcollina do you have one in mind or are you suggesting implementing one? |
I maintain a pure rust bignum library, happy to chat and help if useful :) |
@hugomrdias On AssemblyScript we have bignum library btw: https://github.com/MaxGraey/bignum.wasm. But it still missing some methods for u256/i256 classes but btw |
Assuming the implementation is sensible it doesn't seem like we'd gain much from writing our own then. |
Moving from WebAssembly to JS and viceversa cost time. Moving back-and-forth for every number operation is going to be more costly than moving back-and-forth for each chunk of data. I'd still explore compiling https://github.com/fd0/lbfs/tree/bdf4f17d23b68536e7805c88e269026c74c32d59/liblbfs to WebAssembly and measuring throughput. |
just got as wasm rabin working https://github.com/hugomrdias/rabin-wasm @MaxGraey would be awesome if you could check if i left some performance hanging on the assemblyscript side. its my first assemblyscript project so the code can probably be improved. |
@hugomrdias LGTM. Minor tips:
unchecked(lengths[chunk_idx++] = <i32>this.chunk_length)
// or
let t = unchecked(arr[i])
|
@MaxGraey i get an error memory access out of bounds with the unchecked. Is unchecked only for i32[] or am i doing something wrong ? |
@hugomrdias it accept for any kind of array. About error. I saw you use "allocator/tlsf" it has some bugs in muster which cause memory corruption sometimes. But this memory issues already fixed in For example. You allocate may be better use: new Int32Array(Math.ceil(buf.length/(this.max - this.min))) I'm not sure |
@MaxGraey that allocation is weird ... because i don't know before hand the size of the array so i allocate the maximum possible size and remove the extra 0s after. |
You could wait new release of AS which allow usual arrays during export or you could use temporal dynamic |
@MaxGraey thank you!! problem fixed and regarding the array auto grow ill wait for the next release for now. i pushed a new version with lots of goodies, browser support, types, umd bundle, a wasm2commonjs tool so i can just require in the browser and node. This wasm2js tool will be extracted into a new module to be re-used, could be helpful to others if we add it to the AS wiki. |
Also I recommend use |
@MaxGraey what about shinkLevel ? |
-O3z for --optimizeLevel 3 and --shrinkLevel 2 ? |
yes, |
final results show with Package size: 4.66 KB with all dependencies, minified and gzipped (inlined in a single file for easier distribution) |
Closing this one now, thanks for all the input! We have WASM Rabin now and long.js might be slower and a bunch of work to refactor and use everywhere so lets stick with bignumber.js for now! |
Relevant news: Firefox 68 shipped support for
|
I was porting rabin to JavaScript to add support for rabin chunking in the browser - the c algorithm uses lots of bitwise operations on
uint64_t
types which JavaScript cannot do because lol JavaScript 'numbers'.I used the
long.js
module to do this. A passing @olizilla said 'Why don't you usebignumber.js
like all our other projects?' 'Good point' I said and started to refactor...but then:
Turns out the support for bitwise operations in
bignumber.js
is pretty poor and there's not a lot of movement to add support. There have been a few attempts but no successes - see MikeMcl/bignumber.js#2 and the issues linked from MikeMcl/bignumber.js#229long.js
has support for all bitwise operations and also in a nicer* way for those thatbignumber.js
does support (e.g.long.shiftLeft(8)
vsbig.shiftedBy(-8)
).It's also smaller - the minified versions shipped with both modules are 9.6k (
long.js
) vs 18k (bignumber.js
).I don't want to propose swapping
bignumber.js
forlong.js
everywhere but it doesn't make a lot of sense to have two modules for this.Anyone got any thoughts? @ipfs/repos-javascript
* = completely subjective
The text was updated successfully, but these errors were encountered: