frenetic-lang/frenetic — pull request #352 by seliopou (2014-09-24 14:11:22+00:00)
Title: double compiler speed

The compare function in the `Headers` module was not short-circuiting upon discovering a non-equal field. Adding the short-circuiting produces roughly a 2x speedup in the LocalCompiler. This result came from profiling the LocalCompiler using the policy that you can find below. The average (n=3) total running before the change was 11.647s, and the total running time after the change was 5.551s.

```
filter ethTyp = 0x806; (filter ethTyp = 0x806; port := host) |
filter not ethTyp = 0x806; (filter ethSrc = ff:ea:bb:ad:ab:ba; port := probe) |
filter not ethSrc = ff:ea:bb:ad:ab:ba;
(filter switch = 4;
(filter ethDst = 00:00:00:00:00:05; port := 4 |
(filter ethDst = 00:00:00:00:00:04; port := 4 |
(filter ethDst = 00:00:00:00:00:03; port := 4 |
(filter ethDst = 00:00:00:00:00:02; port := 4 |
filter ethDst = 00:00:00:00:00:01; port := 4))) |
(filter ethDst = ff:ff:ff:ff:ff:ff or
not
(ethDst = 00:00:00:00:00:05 or
(ethDst = 00:00:00:00:00:04 or
(ethDst = 00:00:00:00:00:03 or
(ethDst = 00:00:00:00:00:02 or ethDst = 00:00:00:00:00:01))));
(filter port = 4; (port := 3 | (port := 2 | port := 1)) |
(filter port = 3; (port := 4 | (port := 2 | port := 1)) |
(filter port = 2; (port := 4 | (port := 3 | port := 1)) |
(filter port = 1; (port := 4 | (port := 3 | port := 2)) | drop)))) |
filter not (ethSrc = 00:00:00:00:00:05) and
(not (ethSrc = 00:00:00:00:00:04) and
(not (ethSrc = 00:00:00:00:00:03) and
(not (ethSrc = 00:00:00:00:00:02) and
not (ethSrc = 00:00:00:00:00:01))));
port := learn)) |
(filter switch = 3;
(filter ethDst = 00:00:00:00:00:04; port := 1 |
(filter ethDst = 00:00:00:00:00:03; port := 4 |
(filter ethDst = 00:00:00:00:00:02; port := 4 |
filter ethDst = 00:00:00:00:00:01; port := 4)) |
(filter ethDst = ff:ff:ff:ff:ff:ff or
not
(ethDst = 00:00:00:00:00:04 or
(ethDst = 00:00:00:00:00:03 or
(ethDst = 00:00:00:00:00:02 or ethDst = 00:00:00:00:00:01)));
(filter port = 4; (port := 3 | (port := 2 | port := 1)) |
(filter port = 3; (port := 4 | (port := 2 | port := 1)) |
(filter port = 2; (port := 4 | (port := 3 | port := 1)) |
(filter port = 1; (port := 4 | (port := 3 | port := 2)) | drop)))) |
filter not (ethSrc = 00:00:00:00:00:04) and
(not (ethSrc = 00:00:00:00:00:03) and
(not (ethSrc = 00:00:00:00:00:02) and
not (ethSrc = 00:00:00:00:00:01)));
port := learn)) |
(filter switch = 2;
(filter ethDst = 00:00:00:00:00:04; port := 4 |
(filter ethDst = 00:00:00:00:00:03; port := 3 |
(filter ethDst = 00:00:00:00:00:02; port := 2 |
filter ethDst = 00:00:00:00:00:01; port := 1)) |
(filter ethDst = ff:ff:ff:ff:ff:ff or
not
(ethDst = 00:00:00:00:00:04 or
(ethDst = 00:00:00:00:00:03 or
(ethDst = 00:00:00:00:00:02 or ethDst = 00:00:00:00:00:01)));
(filter port = 4; (port := 3 | (port := 2 | port := 1)) |
(filter port = 3; (port := 4 | (port := 2 | port := 1)) |
(filter port = 2; (port := 4 | (port := 3 | port := 1)) |
(filter port = 1; (port := 4 | (port := 3 | port := 2)) | drop)))) |
filter not (ethSrc = 00:00:00:00:00:04) and
(not (ethSrc = 00:00:00:00:00:03) and
(not (ethSrc = 00:00:00:00:00:02) and
not (ethSrc = 00:00:00:00:00:01)));
port := learn)) |
(filter switch = 1;
(filter ethDst = 00:00:00:00:00:04; port := 2 |
(filter ethDst = 00:00:00:00:00:03; port := 1 |
(filter ethDst = 00:00:00:00:00:02; port := 1 |
filter ethDst = 00:00:00:00:00:01; port := 1)) |
(filter ethDst = ff:ff:ff:ff:ff:ff or
not
(ethDst = 00:00:00:00:00:04 or
(ethDst = 00:00:00:00:00:03 or
(ethDst = 00:00:00:00:00:02 or ethDst = 00:00:00:00:00:01)));
(filter port = 3; (port := 2 | port := 1) |
(filter port = 2; (port := 3 | port := 1) |
(filter port = 1; (port := 3 | port := 2) | drop))) |
filter not (ethSrc = 00:00:00:00:00:04) and
(not (ethSrc = 00:00:00:00:00:03) and
(not (ethSrc = 00:00:00:00:00:02) and
not (ethSrc = 00:00:00:00:00:01)));
port := learn)) |
drop))))
```