[3/4] reduce cookie tracking: count cookies

add an efficient cookie counting function

Change-Id: I9462bd8c74eec0e69ca90bcdb6143501ffe728cc