-
Notifications
You must be signed in to change notification settings - Fork 105
fix delete function #606
fix delete function #606
Conversation
just added a benchmark. Old code
New Code
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes a lot of sense. I'm still surprised by how big the performance difference is though, good find
- when deleting a branch node, we first walk up the tree to delete children. As all siblings and the parents are already being deleted, there is no need to walk back down the tree removing the children and any empty branches.
@@ -279,6 +279,30 @@ func TestDelete(t *testing.T) { | |||
}) | |||
} | |||
|
|||
func TestDeleteWithLotsOfSeries(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should just put 10k or 1M or whatever in the title instead of "lots"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also what's the point of doing this many in a unit test anyway? doing it with 100 instead of 100k invokes all the exact same code, but runs the test in 4ms instead of 800ms on my computer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the complexity of the old code was exponential, O(n^2). But this new code is O(n)
With the old code, it would take many minutes to delete 100k items from the index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in #609
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my point is that the purpose of unit tests is testing functionality. if you want to verify performance criteria (such as x must take no more than y time) then that is what benchmarks are for.
data.SetId() | ||
ix.AddOrUpdate(data, 1) | ||
} | ||
Convey("when deleting 1 million series", t, func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's 100k.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was 1million, but that broke circleci due to needing too much ram.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in #609
children. As all siblings and the parents are already being deleted,
there is no need to walk back down the tree removing the children and
any empty branches.