Speed up for loops over empty tables

Description

topic/jazoff/speedup-for

This change doubles the performance of for loops over empty tables.

A bro binary that prints out this size shows for
testing/external/bro-testing/2009-M57-day11-18.trace, for loops are run
over tables of size:

11477 for size 0
8371 for size 1
1227 for size 3
239 for size 2
141 for size 6
57 for size 5
10 for size 4
5 for size 7
2 for size 13
2 for size 8
2 for size 11
1 for size 9

~53% of the for loops were across an empty table. These loops come from
things like the for loop in the http script over c$http_state$pending

This change prevents the creation of an iteration cookie entirely if the
table is empty.

Using this test script:

const scan_ports: table[port] of count = { };

local x = 0;
while ( x < 20000000 ) {
for(p in scan_ports) {
}
++x;
}

$ time bro.orig -b ___bench.bro

real 0m10.732s
user 0m10.415s
sys 0m0.113s

$ time bro.nocookie -b ___bench.bro

real 0m4.694s
user 0m4.464s
sys 0m0.086s

Environment

None

Assignee

Jon Siwek

Reporter

Justin Azoff

Labels

None

External issue ID

None

Components

Fix versions

Affects versions

Priority

Normal
Configure