paulmillr / noble-hashes

Audited & minimal JS implementation of hash functions, MACs and KDFs.
https://paulmillr.com/noble
MIT License
545 stars 46 forks source link

Tweak size #63

Closed jeetiss closed 1 year ago

jeetiss commented 1 year ago

I applied some optimizations to reduce bundle size:

sizes (with all dependencies, minified and gzipped):

blake2b from blake2b
Size:         3 kB      →   2.71 kB

blake2s from blake2s
Size:         2.75 kB   →   2.31 kB

blake3 from blake3
Size:         4.22 kB   →   3.19 kB

hmac from hmac
Size:         1.03 kB   →   891 B

hkdf from hkdf
Size:         1.25 kB   →   1.11 kB

pbkdf2 from pbkdf2
Size:         1.47 kB   →   1.33 kB

pbkdf2Async from pbkdf2
Size:         1.54 kB   →   1.41 kB

ripemd160 from ripemd160
Size:         2.15 kB   →   1.98 kB

scrypt from scrypt
Size:         4.32 kB   →   4.13 kB

scryptAsync from scrypt
Size:         4.39 kB   →   4.2 kB

sha256 from sha256
Size:         2.45 kB   →   2.18 kB

sha512 from sha512
Size:         4.09 kB   →   3.44 kB

sha1 from sha1
Size:         1.82 kB   →   1.65 kB

sha3_224 from sha3
Size:         2.06 kB   →   1.79 kB

sha3_256 from sha3
Size:         2.06 kB   →   1.79 kB

sha3_384 from sha3
Size:         2.06 kB   →   1.79 kB

sha3_512 from sha3
Size:         2.06 kB   →   1.79 kB

keccakP from sha3
Size:         2.06 kB   →   705 B

keccak_256 from sha3
Size:         2.06 kB   →   1.79 kB

keccak_384 from sha3
Size:         2.06 kB   →   1.79 kB

keccak_512 from sha3
Size:         2.06 kB   →   1.79 kB

cshake128 from sha3-addons
Size:         2.32 kB   →   2.04 kB

cshake256 from sha3-addons
Size:         2.32 kB   →   2.04 kB

kmac128 from sha3-addons
Size:         2.5 kB    →   2.2 kB

kmac256 from sha3-addons
Size:         2.5 kB    →   2.19 kB

k12 from sha3-addons
Size:         2.51 kB   →   2.24 kB

m14 from sha3-addons
Size:         2.51 kB   →   2.24 kB

argon2id from argon2
Size:         4.9 kB    →   4.6 kB

eskdf from eskdf
Size:         5.43 kB   →    5.28 kB

i used #62 to test changes

paulmillr commented 1 year ago

run big-endian check in every entry and mark it as sideEffect

why? does sideEffects: false in package.json help us in any way? i've thought only PURE annotations do.

jeetiss commented 1 year ago

made a little demo with stackblitz to test that behavior

jeetiss commented 1 year ago

@paulmillr Hello, Are you interested in those changes? I wanna create some PR for the curves package.

paulmillr commented 1 year ago

@jeetiss thanks for the pull request. It's good. Yes, I am interested.

I am concerned with moving-out big-endian check into the separate file.

It's always used. Can't we just keep it in utils? I assume sideEffects: false remove it, but what else do they remove?

paulmillr commented 1 year ago

Please don't make curves PR until we merge the current one, don't want you to do work that won't be merged.

jeetiss commented 1 year ago

I think it should be better to split this PR into a couple:

The first two are not so controversial and we can discuss options for sideEffects after