[1/4] reduce cookie tracking: count cookies

add an efficient cookie counting function

Change-Id: I2430236aa125d1833553d9050368ddb87816bda5