How to calculate indexedDB table size in chrome? How to calculate indexedDB table size in chrome? google-chrome google-chrome

How to calculate indexedDB table size in chrome?


The Indexed DB API does not provide a way to query the size of databases (or stores/indexes). Translating keys and values into bytes is also something performed by the browser and is not visible to script. So the script must be doing an approximation, e.g. computing the size of all keys and values in a store when serialized as strings.

The Indexed DB implementation in Chrome uses a backing store called leveldb which has various size optimizations, such as key prefix compression and value compression using another library called "snappy". Strings can also be serialized as bytes in numerous ways (e.g. JS strings are 16-bits per character, which could be naively stored as 2 bytes per character or UTF-8 encoded to 1-4 bytes per character). The backing store also lazily compacts when data is deleted or overwritten, so it may end up taking more space than it needs temporarily.

None of these optimizations are visible to script either, and all will vary cross browsers, so the approximation will be... approximate. Given all of this, an estimate of 389MB vs. the 255MB the browser reports is pretty good!

In Chrome we're experimenting with a per-type breakdown reported via the navigator.storage.estimate() API that would give the exact value for each storage type (e.g. Indexed DB vs. Cache vs. ...), although it still would not give per-database or per-object store values.