Re: RESEND: NSMetadataItem performance issues
Re: RESEND: NSMetadataItem performance issues
- Subject: Re: RESEND: NSMetadataItem performance issues
- From: Vince DeMarco <email@hidden>
- Date: Tue, 2 Aug 2005 16:46:55 -0700
On Aug 2, 2005, at 4:31 PM, Hamish Allan wrote:
I'm having strange performance issues with NSMetadataItems. To
demonstrate I've put an example project here: http://
igor.gold.ac.uk/~map01ra/SpotTest.zip -- it would be great if
someone could confirm or deny that the problem occurs on their
machine too, and perhaps offer an explanation!
The application presents a window with an NSSearchField and a
table. Entering something into the search field causes an
NSMetadataQuery to be performed with an NSPredicate
"(kMDItemTextContent like[cd] something*)".
As each set of results come in, I'm storing NSMetadataItems in an
NSMutableDictionary under keys of their kMDItemPaths. This
obviously slows down proceedings a little but not to that great an
extent. For instance, in a query returning about 20,000 results:
[Session started at 2005-07-28 02:01:26 +0100.]
2005-07-28 02:01:35.472 SpotTest[10713] beginQuery: 0 results
2005-07-28 02:01:36.333 SpotTest[10713] updateResultsTable: storing
results 0 through 1004
2005-07-28 02:01:36.506 SpotTest[10713] updateResultsTable:
dictionary count 1005
2005-07-28 02:01:40.880 SpotTest[10713] updateResultsTable: storing
results 1005 through 2000
2005-07-28 02:01:41.075 SpotTest[10713] updateResultsTable:
dictionary count 2001
2005-07-28 02:01:43.299 SpotTest[10713] updateResultsTable: storing
results 2001 through 3005
2005-07-28 02:01:43.452 SpotTest[10713] updateResultsTable:
dictionary count 3006
2005-07-28 02:01:46.022 SpotTest[10713] updateResultsTable: storing
results 3006 through 3951
2005-07-28 02:01:46.528 SpotTest[10713] updateResultsTable:
dictionary count 3952
2005-07-28 02:01:47.826 SpotTest[10713] updateResultsTable: storing
results 3952 through 4890
2005-07-28 02:01:48.456 SpotTest[10713] updateResultsTable:
dictionary count 4891
2005-07-28 02:01:49.542 SpotTest[10713] updateResultsTable: storing
results 4891 through 5900
2005-07-28 02:01:50.207 SpotTest[10713] updateResultsTable:
dictionary count 5901
2005-07-28 02:01:50.713 SpotTest[10713] updateResultsTable: storing
results 5901 through 6919
2005-07-28 02:01:51.613 SpotTest[10713] updateResultsTable:
dictionary count 6920
2005-07-28 02:01:52.433 SpotTest[10713] updateResultsTable: storing
results 6920 through 7954
2005-07-28 02:01:52.995 SpotTest[10713] updateResultsTable:
dictionary count 7955
2005-07-28 02:01:53.183 SpotTest[10713] updateResultsTable: storing
results 7955 through 20544
2005-07-28 02:01:58.990 SpotTest[10713] updateResultsTable:
dictionary count 20545
2005-07-28 02:01:58.991 SpotTest[10713] endQuery: 20545 results
The pause between the first and second batches of results is where
the table is drawn, requiring about 50 calls to -[NSMetadataItem
valueForAttribute:] which slows it down . And adding the 12,000
results that all come in together at the end takes a little time.
But what's wierd is what happens when you do exactly the same
search a second time (without doing anything else in between):
2005-07-28 02:02:22.739 SpotTest[10713] beginQuery: 0 results
2005-07-28 02:02:22.924 SpotTest[10713] updateResultsTable: storing
results 0 through 1004
2005-07-28 02:02:23.813 SpotTest[10713] updateResultsTable:
dictionary count 20545
2005-07-28 02:03:12.278 SpotTest[10713] updateResultsTable: storing
results 1005 through 2000
2005-07-28 02:03:13.221 SpotTest[10713] updateResultsTable:
dictionary count 20545
2005-07-28 02:03:13.441 SpotTest[10713] updateResultsTable: storing
results 2001 through 3005
2005-07-28 02:03:14.384 SpotTest[10713] updateResultsTable:
dictionary count 20545
2005-07-28 02:03:14.563 SpotTest[10713] updateResultsTable: storing
results 3006 through 3951
2005-07-28 02:03:15.335 SpotTest[10713] updateResultsTable:
dictionary count 20545
2005-07-28 02:03:15.529 SpotTest[10713] updateResultsTable: storing
results 3952 through 20544
2005-07-28 02:03:32.711 SpotTest[10713] updateResultsTable:
dictionary count 20545
2005-07-28 02:03:32.712 SpotTest[10713] endQuery: 20545 results
The first batch of results gets added to the dictionary okay, but
then the table redrawing code takes absolutely ages (30 seconds in
this example). If you put NSLog() statements around the
valueForAttribute: calls in
tableView:objectValueForTableColumn:row: it transpires that each
one is taking just over 1 second to execute -- don't know if this
is related to the batching interval as setting the batching
interval seems to have no effect.
It seems you need a few thousand search results for this problem to
manifest itself, and it may happen at any point -- in this
particular search it always happens in the first batch of the
second identical search, but in other searches it might happen
sooner, later, or not at all. And if you never store the
NSMetadataItems in the dictionary it still happens, but not if you
don't ever fetch the kMDItemPaths.
kMDItemPaths isn't cached its generated on the client as you need it.
So asking for kMDItemPath is going to be slow, only ask for the Path
of an item when you absolutely need it don't do it always.
Vince
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden