megahash
megahash copied to clipboard
Improve performance of a few types
Hey,
I ended up focusing on some improvements for the less important data types and flags. Additionally i added some more tests and updated dependencies because why not.
Anyways feel free to take a look, test and pick what you like. If you don't like some specific change let me know and i'll revert
Cheers!
package.json
Update dependencies
test.js
Added tests for:
- Empty String
- BigInt > 64 bit
- NaN
- Infinity
- Undefined
- Function
test-bench2.js
Added benchmarks for measuring performance of different data types
main.js
Changes:
- separate and clarify flag-only data types
- added flags for: true, false, big bigint, nan, infinity, undefined, function
- changed Buffer.alloc to Buffer.allocUnsafe (faster)
- added support for big bigint (>64bit, stored as hex buffer)
- serialize functions and retrieve actual functions instead of string representation (breaking change)
- store undefined as flag and retrieve actual undefined instead of "undefined" (breaking change)
hash.cc
Added short-circuiting for flag-only types
Performance changes:
- Numbers -> 50% faster writes
- Booleans -> 100% faster writes and 200% faster reads
- Bigint -> 50% faster writes
- Big Bigint -> no longer throws, performance is a bit slower than strings
- Null -> 50% faster writes, 200% faster reads
- NaN -> 100% faster writes, 200% faster reads
- Infinity -> 100% faster writes, 200% faster reads
- Undefined -> 50% faster writes, 200% faster reads
- Function -> now returns an actual function, performance is a bit slower than objects
Hey @timotejroiko, thanks so much for this! I'll take a look as soon as I have some time.
Hey @timotejroiko,
So I have to apologize. I had a bunch of MegaHash changes in my local repo from many months ago that I didn't finish, and kind of forgot about. I really wanted to get those committed, pushed and tagged before I worked on your fork.
Part of these changes was cleaning up the repo folders a bit, and I moved the test scripts into a new test/ subdirectory, and completely redesigned the benchmarking script.
Would it be possible for you to move your test script into there as well? Also, can we rename it from test-bench2.js to something like test-types.js?
I think most of your other changes are "mergeable", and won't conflict with what I changed.
Thanks, and sorry!
no worries :) im working on some other stuff but i'll get back on it soon.
i've rebased and moved the file to the test folder, let me know if theres anything else i can do :)
Any update on these @jhuckaby? These PRs look pretty great in what they can provide for the repo