josdejong / mathjs

An extensive math library for JavaScript and Node.js
https://mathjs.org
Apache License 2.0
14.41k stars 1.24k forks source link

Custom build? #882

Closed focussing closed 7 years ago

focussing commented 7 years ago

Hello Jos, (goedemorgen)

What a great library!!

The current (min) build is around 470kB. For my application (Appcelerator Titanium) this is quite large, that is appears to be hanging. After 30 minutes it continues. Can I make a custom build (or could you help me with that) which only contains the functions I use? This is important for me, currently this blocks releasing a test app for my customer...

I use bignumbers only with the following functions:

This is my code:

var PINprime = math.bignumber('0x3A8F05AD');
var PINrnd = math.bignumber('0x239ca5b6c7ab918d');
var lowWordMask = math.bignumber('0x00000000ffffffff');

for (var i = 0; i < 12; i++) {
  var pin = math.bignumber(PIN[i]);
  PINrnd = math.bitXor(PINrnd, pin);
  PINrnd = math.bitXor(math.multiply(math.bitAnd(PINrnd, lowWordMask), PINprime), math.rightArithShift(PINrnd, 32));
}

console.log('out dec:', PINrnd.toString());

Looking forward to hearing from you.

focussing commented 7 years ago

I have commented out all functions, the expression parser that I do not use, and finally end up with a math.min.js file of 208kB. This file has reduced the build time from almost an hour, to 2 minutes. This is off course a lot, but 2 minutes to wait before every build is long compared to the 12 seconds it was...

I cannot see a way of reducing it more. Tried to comment out the matrix and complex numbers parts, but that gives errors during npm build. However I can imagine that removing these types will help a lot... Is there a way to do that?

Best regards, Raymond

josdejong commented 7 years ago

I think you're asking two questions here:

  1. Even a custom bundle is quite large That's true, reason is mainly that when you include for example math.add, you also include all datatypes like Matrix, Complex, BigNumber, which are quite large. It is possible to strip the custom build further, though it requires more work: you can instruct the bundler that you use (like webpack or browserify) to exclude specific files or paths with wildcards.
  2. The build time is very long in my setup I don't know what sort of setup you have. For reference: the default bundling script of math.js takes about 2 seconds to bundle and 25 seconds to minify on my machine. Some ideas:
    • Adjust your setup to only bundle and not minify when in development mode
    • Bundle+minify mathjs only once beforehand in a separate step, and do not bundle it again with every build of your development setup
focussing commented 7 years ago

1) okay... so it is possible but not easy/fast. Any suggestions how to do that? You are using gulp so that itself would be easy. Otherwise I will continue with what I have now.

2) I use mathjs in an APP development environment, and building the APP when mathjs included takes a lot of time to build. Building mathjs itself is fast.

Thanks for your reply!

josdejong commented 7 years ago

I think the best way to start stripping off parts of math.js that you don't need is:

I'm curious to hear whether you can make it work for your use case...

josdejong commented 7 years ago

Just a stupid question: if you're just using a few BigNumber functions, can't you just use the BigNumber library used by math.js instead (decimal.js)?

focussing commented 7 years ago

NOT a stupid question :) this might be a good opportunity, I will surely take a look into that. I can easily setup a test with decimal.js. Thanks for pointing me to that direction.

In the meantime I tested with the n64 library which also gives good results.

josdejong commented 7 years ago

sounds good!

josdejong commented 7 years ago

I think we can close this issue right?

focussing commented 7 years ago

Ok we can. Thank you 👍🏻

Best regards, Mit freundlichen Grüßen, Met vriendelijke groet, Raymond Verbruggen

FOCUSSING B.V. Mispel 8 7621 WB Borne Netherlands +31 6 250 500 69 mail@focussing.nl www.focussing.nl

Op 29 jul. 2017 om 10:56 heeft Jos de Jong notifications@github.com het volgende geschreven:

I think we can close this issue right?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

josdejong commented 7 years ago

okido