views:

97

answers:

2

SQLite is a great little database, but I am having an issue with it on Windows. It can take up to 50 seconds to perform a query on a 100MB database the first time the application is launched. Subsequent loads take 10% of that time.

After some discussions on the SQLite mailing list, I am told "The bug is in Windows. It aggressively pre-caches big database files
-- reads in big chunks of the files -- to make it look as if programs
like Outlook are better than they really are. Unfortunately although
this speeds up some programs it makes others act jerky because they
have no control over how much is read when they ask for just a few
bytes of file."

This problem is compounded because there is no way to get progress information while all this is happening from SQLite, so my users think something is broken. (I could display a dummy progress report, but that is really cheesy for a sharp tool.)

I believe there is a way to turn the pre-caching off globally, but is there some way around this programmatically?

+1  A: 

I don't know how to fix the caching problem, but 50 seconds sounds extreme. If the query itself takes 10% of that, that means 45 seconds to load a 100mb file. Even if Windows does read in the entire file in one go, that shouldn't take more than a couple of seconds given normal harddrive speeds.

Is the file very fragmented or something?

It sounds to me like there's more than just precaching at play here.

jalf
Definitely. I've worked with similar size sqlite databases and didn't experience this problem.
Krugar
Yes I think you are right. The Query is not simple. I suspect that SQLite is doing something, but there is no way to know what (without getting into its code which don't want to do). Since subsequent requests are at most 20% of this time, it's obviously a one time event.
Mike Trader
can't you just run it through a profiler and see which function(s) eat up all that time?
jalf
Good Idea, Never done that. Can you reccomend one pls
Mike Trader
The top end version of Visual Studio comes with one built in. Otherwise, Intel has vTune (costs money, but I think there's a free trial version), and AMD offers CodeAnalyst (for free as far as I know).
jalf
+1  A: 

I'm too having the same problem with my first query. The problem returns after not querying the database for a long time. It seems to be a memory caching problem. My software runs 24/7 and every once in a while the user performs the SELECT query. I am also performing the query on a database of the same size.

Matthew Sannes