pub fn lookup(name: &[u8]) -> Option<&'static Spec>Expand description
The command called name, whatever case the client spelled it in.
This used to walk the whole table comparing lengths, and the cost of that was
not what it looked like. The table is written in rough order of how often a
command is sent, so set and get were the first two entries and cost one
compare, but exists is the hundred and forty ninth and del the hundred and
forty seventh, and every one of those compares was paid twice per command,
once to work out the key hash and once to dispatch.
Measured, that walk was 104 nanoseconds a command, which is more than a whole
GET costs end to end. EXISTS on a missing key ran at three and a half
times GET and almost none of the difference was the command: short
circuiting the lookup alone took it from 8.7 microseconds a batch of sixty
four to 2.0, and left it faster than GET, which it should be, because it
does less.
So this is one multiply and one load into two kibibytes, and then the same name compare it always ended with. What it costs the hot commands is a multiply they did not use to pay and a load that hits, and what it saves the rest is the whole walk.