stream/segments: speed up inserts

Don't try to do a 'fast path' by checking RB_MAX. RB_MAX walks the
tree which means it can be quite expensive. This cost would be paid
for virtually every data segment. The actual insert that follows would
walk the tree again.

Instead, simply insert it. There is a slight cost of the unnecessary
overlap check, but this is much less than the tree walk in a full
tree.
pull/3479/head
Victor Julien 7 years ago
parent f4ff33969e
commit 51ce03e76a

@ -178,16 +178,6 @@ static int DoInsertSegment (TcpStream *stream, TcpSegment *seg, TcpSegment **dup
return 0;
}
/* insert the segment in the stream tree using this fast track, if seg->seq
is equal or higher than last segments tail. */
TcpSegment *last = RB_MAX(TCPSEG, &stream->seg_tree);
if (last && SEQ_GEQ(seg->seq, (uint32_t)SEG_SEQ_RIGHT_EDGE(last)))
{
SCLogDebug("seg beyond tree tail, append");
TCPSEG_RB_INSERT(&stream->seg_tree, seg);
return 0;
}
/* insert and then check if there was any overlap with other segments */
TcpSegment *res = TCPSEG_RB_INSERT(&stream->seg_tree, seg);
if (res) {

Loading…
Cancel
Save