honnold
Quickly traverse large js objects without the weight
Usage
const honnold = ; const obj = some: deeply: nested: object: prop1: true prop2: 'hi' ; // Basic traversal;// > true// > hi // Remove all leaves with a specific value; // Remove all leaves with a specific key; // Replace all leaves with a specific value; // Remove all leaves beyond a specific depth; // Loop through all internal nodes;
Why?
I thought the existing traversal libraries were bloated, slow, and difficult to use. Through benchmarking, I've learned the existing libraries (namely tree-crawl
) are pretty fast, but honnold
is still useful if size is important or you want a simpler interface.
Stats
- honnold
- traverse
- tree-crawl
Leaf traverse (100 wide x 20 deep):
honnold x 1,495 ops/sec ±1.33% (90 runs sampled)
traverse x 591 ops/sec ±3.59% (87 runs sampled)
tree-crawl x 2,108 ops/sec ±0.78% (91 runs sampled)
Fastest is tree-crawl
Leaf with keys traverse (100 wide x 20 deep):
honnold x 831 ops/sec ±2.19% (89 runs sampled)
traverse x 559 ops/sec ±1.25% (92 runs sampled)
tree-crawl - N/A:
Fastest is honnold
Leaf with depth traverse (100 wide x 20 deep):
honnold x 868 ops/sec ±2.10% (91 runs sampled)
traverse x 558 ops/sec ±2.59% (90 runs sampled)
tree-crawl x 2,087 ops/sec ±0.59% (94 runs sampled)
Fastest is tree-crawl
Internal node traverse (100 wide x 20 deep):
honnold x 1,434 ops/sec ±2.57% (94 runs sampled)
traverse x 565 ops/sec ±0.43% (93 runs sampled)
tree-crawl x 2,044 ops/sec ±1.75% (93 runs sampled)
Fastest is tree-crawl
License
MIT