persistent-hash-trie
persistent-hash-trie copied to clipboard
Cache hash results?
As a user, I don't want speed to be impacted adversely by constantly re-hashing the same keys.
Acceptance:
- explore options and impact of memoizing the internally used hash function.
To test, I've replaced the definition of gen-keys/.words with something that creates a list of ints (which means that we can expect keys to be hashed). I've memoized the hash function using lodash's memoize function. (tests still pass).
The benchmark results indicate no gain:
assoc property with Trie of 1
//-------------------------//
current : 667,883.48 ± 2.80% ops/sec
v0.3.1 : 677,451.38 ± 6.77% ops/sec
assoc property with Trie of 10
//-------------------------//
current : 214,230.04 ± 2.07% ops/sec
v0.3.1 : 347,176.57 ± 2.63% ops/sec
assoc property with Trie of 100
//-------------------------//
current : 124,986.17 ± 3.15% ops/sec
v0.3.1 : 67,337.27 ± 3.19% ops/sec
assoc property with Trie of 1000
//-------------------------//
current : 38,577.81 ± 1.21% ops/sec
v0.3.1 : 65,089.61 ± 3.16% ops/sec
dissoc property with Trie of 1
//-------------------------//
current : 365,027.33 ± 2.83% ops/sec
v0.3.1 : 428,897.20 ± 2.44% ops/sec
dissoc property with Trie of 10
//-------------------------//
current : 159,094.52 ± 1.33% ops/sec
v0.3.1 : 255,686.19 ± 1.39% ops/sec
dissoc property with Trie of 100
//-------------------------//
current : 100,180.55 ± 1.91% ops/sec
v0.3.1 : 38,930.46 ± 1.91% ops/sec
dissoc property with Trie of 1000
//-------------------------//
current : 25,606.33 ± 2.14% ops/sec
v0.3.1 : 39,129.83 ± 1.00% ops/sec
has property with Trie of 1
//-------------------------//
current : 6,090,564.19 ± 0.87% ops/sec
v0.3.1 : 11,209,269.92 ± 0.97% ops/sec