Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to make SPList.Add() and SPListItem.Update() go faster

16 views
Skip to first unread message

Stephen Walch

unread,
Oct 13, 2005, 8:55:20 AM10/13/05
to
I have written a fairly straigtforward routine to import a lot of WSS List
Items using tha managed server-side APIs. It basically amounts to:

foreach(...)
{
SPList list = ...;
SPListIitem item = list.Add();
item[...] = ...;
...
item.Update();
}

I have found that each iteration through this loop gets a lot slower
(expotentially?) as the list gets longer.

Starting with an empty generic list with about 8 custom fields, I get these
results:

Adding items 1 - 500: 24 secs
Adding items 501 - 1000: 65 secs
Adding items 1001 - 1500: 181 secs
Adding items 1501 - 2000: 309 secs
Adding items 2001 - 2500: 461 secs

This pattern mes me think that there is a lot of indexing, etc., checking
for dumpliactes, going on for each add. Is there a way to suspend these
types of things buring a bulk load operation?

Also, are there any WSS services I could temporarily shut off to to make
bulk loads go faster?

Or is there a whole different approach I should be using?

Thanks in advance!


Bil Simser [SPS MVP]

unread,
Oct 13, 2005, 12:36:17 PM10/13/05
to
For bulk loads like this I use the Lists web service (UpdateListItems)
that let's me batch them together. Creating the CAML for it is a pain
but it's much faster.

--
Bil Simser
SharePoint MVP, BSc., MCSD
Calgary, Alberta
http://weblogs.asp.net/bsimser

"Stephen Walch" <swa...@online.nospam> wrote in message
news:uNA7fV$zFHA...@tk2msftngp13.phx.gbl:

Stephen Walch

unread,
Oct 13, 2005, 7:59:20 PM10/13/05
to
Are there any limitations I should be aware of when using the Web Service
instead of the managed API?

"Bil Simser [SPS MVP]" <bsi...@shaw.ca> wrote in message
news:eBxa9QB0...@tk2msftngp13.phx.gbl...

Bil Simser [SPS MVP]

unread,
Oct 13, 2005, 8:08:58 PM10/13/05
to
It depends on your situation. What I mean is that I wouldn't try adding
1000 items at once using it but beyond *reasonable* acts of programming,
I don't know of any limits. Of course reasonable is a relative term so
YMMV.

--
Bil Simser
SharePoint MVP, BSc., MCSD
Calgary, Alberta
http://weblogs.asp.net/bsimser

"Stephen Walch" <swa...@online.nospam> wrote in message

news:OaSniIF0...@TK2MSFTNGP10.phx.gbl:

Wei-Dong XU [MSFT]

unread,
Oct 13, 2005, 10:56:41 PM10/13/05
to
Hi Stephen,

Since you are using the object model, I assume you only use the utility in
the intranet. So pleae feel free to use that web service. At intranet, the
web service API should work very well.

If any question, post here and I am glad to be of any assistance for you.

Best Regards,
Wei-Dong XU
Microsoft Product Support Services
This posting is provided "AS IS" with no warranties, and confers no rights.
It is my pleasure to be of assistance.

colinb

unread,
Oct 14, 2005, 9:14:06 AM10/14/05
to
Stephen,

You can process batch data through the OM using the
SPWeb.ProcessBatchData method

Assuming you have a SPWeb object called web this code will create an
announcement

Guid listguid=web.Lists["Announcements"].ID;
string xmlcaml="<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<Batch>" +
"<Method>" +
"<SetList Scope=\"Request\">" + listguid +"</SetList>" +
"<SetVar Name=\"ID\">New</SetVar>" +
"<SetVar Name=\"Cmd\">Save</SetVar>" +
"<SetVar
Name=\"urn:schemas-microsoft-com:office:office#Title\">Project
Meeting</SetVar>" +
"<SetVar
Name=\"urn:schemas-microsoft-com:office:office#Body\">Project Meeting
Event body</SetVar>" +
"<SetVar
Name=\"urn:schemas-microsoft-com:office:office#Expires\">2005-11-1
9:00:00</SetVar>" +
"</Method>" +
"</Batch>";

string returndata=web.ProcessBatchData(xmlcaml);

Unfortunately the syntax is different from the Web api's.

Now whether this that much quicker I don't know it should be.
If I do bulk imports for migrations I disable indexing and make sure
SQL Server is running nicely i.e run a full maint plan making sure all
the tables are contiguous. Log file performance is crucial for inserts
i.e. make sure the log file is on a different drive to your data and
not using RAID 5.

Colin

Free Flash Slideshow WebPart
http://www.flexnetconsult.co.uk/WebParts/WebParts.htm

0 new messages