Avoid toArray().filter() unless the dataset is tiny.
Summary
Indexed queries in IndexedDB are 10x–1000x faster than linear scans on large datasets. Always use .where() or .orderBy() on indexed fields for scalable, memory-efficient apps.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Using 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