Yomguithereal / baobab

JavaScript & TypeScript persistent and optionally immutable data tree with cursors.
MIT License
3.15k stars 116 forks source link

Option to disable monkeys #488

Closed Tuhis closed 7 years ago

Tuhis commented 7 years ago

Hi,

Adding an option to disable monkeys would add significant performance boost when operating with large trees without monkeys. Currently, during each update the whole updated branch is traversed through in order to find and update monkeys.

I did some performance measurements which showed that a single update took 210ms, of which over 120ms were wasted walking the tree and trying to find monkeys. About 70ms went to freeze and rest for all other stuff.

Br, Tuhis

Yomguithereal commented 7 years ago

Hello @Tuhis. That's weird. I seem to recall that I had a map of the monkeys in the tree so that I could avoid walking the tree when it's not needed. But I guess this is not the case, as your measurements show.

This said, I am open to a PR adding an option to forbid monkeys in a Baobab instance for performance reasons.

Tuhis commented 7 years ago

Weird indeed. If I understood the code correctly, we walk the tree on every update from the updated point onward (except on unset operation). Anyhow, I submitted a simple PR for disabling monkey evaluation. Hopefully you have some time to review it :)

Yomguithereal commented 7 years ago

v2.5.0 is now on npm with your addition. Thansk @Tuhis.