Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree: improved complexity. #457

Merged
merged 1 commit into from Jun 22, 2017
Merged

Tree: improved complexity. #457

merged 1 commit into from Jun 22, 2017

Conversation

ghost
Copy link

@ghost ghost commented Jun 22, 2017

On a trivial benchmark (initialising a tree with a lot of values), this
patch introduces a 10-times speed-up (around 30 seconds to around 3).

This is achieved by removing unrequired structural comparisons when
inserting/removing a value in the tree.

The function add/add_tree/remove try to reduce the pressure on the GC
by not reallocating the tree when the resulting tree is (structurally)
equal to the previous one. But instead of only comparing the inserted
value to the previous value (if it exists), the current implementation
also recursively compare all the nodes on the insertion path.

This patch simplify the insertion/removal, by changing the type of the
recursive function aux. It now returns an option : None when the sub
tree was not modified.

On a trivial benchmark (initialising a tree with a lot of values), this
patch introduces a 20-times speed-up (around 60 seconds to around 3).

This is achieved by removing unrequired structural comparisons when
inserting/removing a value in the tree.

The function `add/add_tree/remove` try to reduce the pressure on the GC
by not reallocating the tree when the resulting tree is (structurally)
equal to the previous one. But instead of only comparing the inserted
value to the previous value (if it exists), the current implementation
also recursively compare all the nodes on the insertion path.

This patch simplify the insertion/removal, by changing the type of the
recursive function `aux`. It now returns an option : `None` when the sub
tree was not modified.
@samoht
Copy link
Member

samoht commented Jun 22, 2017

Thanks a lot!

Something I've been wondering with the tree structure is if we should always prune the empty directories or not. For the Git backend it makes sense (because Git will do it anyway) but maybe there are some use-cases where we are interested in distinguishing empty directories. This could be controlled by an optional argument to Tree.remove ?(keep_empty=false) for instance.

What do you think?

@ghost ghost mentioned this pull request Jun 22, 2017
@samoht samoht merged commit 6d4c363 into mirage:master Jun 22, 2017
@ghost
Copy link
Author

ghost commented Jun 22, 2017

I have no particular usage in mind where preserving empty directories would be useful. But if so, the optional argument looks fine.

@ghost ghost deleted the tree_complexity branch June 22, 2017 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants