Re: Core Data, SQLite, and Housekeeping
Re: Core Data, SQLite, and Housekeeping
- Subject: Re: Core Data, SQLite, and Housekeeping
- From: "I. Savant" <email@hidden>
- Date: Wed, 5 Mar 2008 17:04:16 -0500
> So now the question is this: does Core Data
> implicitly run VACUUM? If so, when? How often? Unfortunately googling
> and archive-searching did not produce any obvious answers to this
> particular question. My guess is that the answer is, "Yes, at every
> save," but I'd like to be sure and I'm not familiar enough with SQLite
> to know how to test this myself. Any takers?
So I remembered the existence of the useful
"-com.apple.CoreData.SQLDebug 1" argument and enabled debugging. I
created a quick Core Data Application with an entity named "Bob" with
a few random attributes. At startup:
---
Loop 10X
{
- Create 1000 Bobs.
- Save.
- Fetch and delete 500 Bobs.
- Save.
}
- Terminate.
---
Creating 1000 and deleting 500 Bobs per cycle, in my mind, ensures
that some good fragmentation is occurring, since the fetches are
unordered (therefore somewhat randomizing Bob deletions). I ran the
application and let it terminate. I took a look at the log and VACUUM
did not appear. I then noted the file size (80896) and manually
vacuumed the store with sqlite3 via:
sqlite3 /path/to/datastore.sql RETURN
VACUUM; RETURN
.quit RETURN
I compared the file sizes and it went from 80896 down to 71680,
verifying that indeed the store was in need of maid service, the
dirty, dirty thing. I repeated the test with 100 cycles. No VACUUM in
the log and manual vacuuming took the file size from 809984 to 727040.
Call me crazy, but I don't believe the VACUUM command is being run at
all on our Core Data SQLite data stores. While hardly conclusive, this
test certainly suggests as much. Perhaps, though, Core Data is smart
enough not to begrudge a few k and runs VACUUM only when it sees a
threshold of fragmentation has been reached?
The real question is, does it really matter if VACUUM is never run?
I'd imagine so, given time and a large, heavily-trafficked store. For
things like iTunes, where you're mostly adding to your store, I can't
see this being a problem, but what about applications that
insert/delete to/from their stores regularly? I'm eyeballing Core Data
for just such a scenario (an intermediary receptacle/queue manager for
a large volume of data from scientific instruments), so I wonder if
I'll have to periodically close the store, vacuum, then re-open. I'll
have a *lot* of Bobs to clean up after ...
--
I.S.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden