p4lang/behavioral-model

Consider implementing something like Tuple Space Search for ternary table lookups

Opened this issue · 0 comments

The current implementation of lookups in ternary tables is to:

  • do an exact match lookup in a cache of full exact match lookup keys that have been searched before
  • if there is a miss in that cache, do a linear scan through all ternary entries, I believe in decreasing priority order, so that you can stop at the first matching entry, if there is one.

However, if you do a test like this:

  • add N entries to a ternary table
  • send N packets to the table, one that should match each of the entries

then it takes O(N^2) time to do that, because every one of the packets misses in the cache.

There are people from Keysight trying to use BMv2 for the DASH project [1] that are trying exactly this for large N, e.g. a few million, but it is unacceptably slow.

They might also be trying this for tables with some ternary keys and some range keys, too. I am not sure.

In either case, using an algorithm like Tuple Space Search would significantly speed up the process of lookups, in the quite common case where there are only relatively few distinct masks used for entries.

If anyone is interested in working on this, I'm happy to give advice.

[1] https://github.com/sonic-net/DASH