What’s the performance impact of using indexes vs linear scans in IndexedDB?
248
07-Jul-2025
Harry
07-Jul-2025Using indexes vs linear scans in IndexedDB has massive performance implications, especially as your dataset grows. Here’s a breakdown:
Indexed Lookup vs Linear Scan
Real-World Example
Suppose you have 10,000 users and want to find the one with email =
x@example.com.1. With Index (
emailindexed)✅ Indexed B-tree lookup → Fast (~milliseconds)
2. Without Index
❌ Loads all 10,000 users into memory → Slow + memory-heavy
Benchmarks (Approximate)
(Browser- and hardware-dependent; rough estimates)
Why Indexed Queries Are Faster
Linear Scan Pitfalls
.toArray()retrieves all records..filter()/.find()works in memory, not on the IndexedDB level.Best Practices
Always index fields that are:
where(),equals(),between())orderBy())toArray().filter()unless the dataset is tiny.Summary