Scaling Melvec for 100K Files
Melvec is a fast-growing local-first desktop app that helps you organize, tag, search, and discover your personal video and photo collections — all using on-device AI. Everything stays on your computer. No cloud. No subscriptions. No data leaving your machine.
I recently pushed the app to its limits with a massive offline library of over 100,000 files. At first, it struggled — freezing, using huge amounts of memory, and sometimes crashing. Here’s how I identified the problems and made Melvec handle large libraries smoothly and reliably.
1. Smarter Memory Use for File Information
The app was storing too little information in its quick-access memory cache. As a result, it kept going back to the database for almost every request, slowing everything down.
Fix: I carefully reviewed what needed to be cached, calculated realistic memory usage, and increased the cache sizes based on how often each piece of data is used. This simple change made a big difference in speed.
2. Loading AI Embeddings in Small Chunks
To find similar videos, Melvec uses AI-generated “embeddings” (numerical representations of your videos). Previously, it tried to load all of them into memory at once — which could use several gigabytes and crash on many computers.
Fix: I switched to loading and processing the embeddings in small batches. The app now handles one chunk at a time, compares it, then moves on. Memory usage stays low no matter how big your library gets.
3. Keeping the App Responsive During Big Updates
When re-indexing a large library for better recommendations, the app would freeze the entire interface for several seconds.
Fix: I added small breathing pauses during the heavy processing. This lets the user interface stay responsive — you can still scroll, click, and use the app normally while the background work continues.
4. Faster Loading of Video Lists
The app used to make many separate database requests for every single video (one for tags, one for playlists, etc.). With 100,000 videos, this added up to hundreds of thousands of slow requests.
Fix: I changed it to fetch everything in just two big, efficient queries. All the data is pulled at once and organized in memory — dramatically reducing loading time.
5. Improved Search with Better Typo Correction
The typo correction feature (which suggests fixes when you mistype a search) used to make many small database requests.
Fix: I grouped the requests so titles and descriptions are fetched together in batches. This cut the number of database calls from hundreds of thousands down to just a few hundred.
6. Smarter Title-Based Recommendations
Finding videos with similar titles previously compared every possible pair — at 100K videos, that meant billions of comparisons. It worked for small libraries but collapsed at scale.
Fix: I built an inverted index (like a smart lookup table for words in titles). The app now only compares videos that actually share common words. This makes title-based suggestions fast and scalable.
7. Better Tag and Playlist Recommendations
Similar issues existed here: slow lookups inside loops and scanning the entire library unnecessarily.
Fix: I added fast lookup tables and a smart “adjacency map” so the app can instantly retrieve related videos without scanning everything.
8. Handling Very Popular Tags
Some tags (like “tutorial” or “nature”) can appear on thousands of files. This created massive lists of comparisons that could crash the app.
Fix: I added a randomized sample collection logic when ever popular tag goes beyond a certain limit. This keeps things fast and fair — newer and older files still have a good chance of appearing in recommendations.
Results
| Problem Area | Before | After |
|---|---|---|
| AI Embedding Memory | Up to ~7 GB | ~7 MB peak per batch |
| Database queries (re-index) | ~200,000 | Just 2 |
| Typo correction queries | ~200,000 | ~500 |
| Title similarity comparisons | ~10 billion | Only relevant candidates |
| Tag/playlist similarity | Very slow (O(N²)) | Much faster |
| Popular tag comparisons | Up to ~50 million | Max ~125K per tag |
| App during re-index | Completely frozen | Fully responsive |
Before: The app became unstable around 30K–50K files.
After: Melvec is now ready to handle 100,000 files smoothly, with fast search, responsive interface, and stable performance.
What I Left for Later
Some features like metadata export/import and initial folder scanning are still slower with very large libraries. But since these are not used constantly (they’re one-time or occasional tasks), I focused first on the parts you use every day. They’ll be improved in the next round. Do report any issues if you find.
Bottom line: Scaling a local media library to 100K files is challenging, but completely doable with smart engineering. Melvec is now much more capable for users with large personal collections — all while staying fully offline and private.
Have you tried running Melvec with a big library? What’s the largest collection you manage locally?