Bad performance when many data

When loading MPP file with a lot of tasks, calendars the performance is quite well. It lasts about second or two. There are about 1600 tasks, 160 resources, 160 calendars, 700 task links, 1500 assignments.

But when creating Project using library methods and adding all data manually the performance is very bad. All the data is identical with the data from MPP file, but added manually. At first adding new task last few milliseconds but later, after adding many tasks the single addition lasts about 0.5s. The similar behavior is with other data types.

Whole creation of project lasts about 15 minutes. It is not acceptable for our scenario. Is it possible to speedup this process? Do you have some batch processing?

Taking tasks as an example at first we create task using Task.Children.Add() method and then we set properties. For example:

var target = parent.Children.Add();
target.Uid = source.Id;
target.Name = source.Name;
target.Start = ToDateTime(source.StartDate);
target.Finish = ToDateTime(source.EndDate);
target.PercentComplete = (int)source.PercentDone;
target.IsMilestone = source.Milestone;
target.IsRollup = source.Rollup;
target.PercentWorkComplete = (int)source.PercentWorkDone;
target.Calendar = project.Calendars.FirstOrDefault(c => c.Uid == source.CalendarId);
if (source.ManuallyScheduled)
    target.ParentProject.CalculationMode = CalculationMode.Manual;
target.ConstraintDate = ToDateTime(source.ConstraintDate);
target.ConstraintType = ConstraintTypes.StringToType[source.ConstraintType];
target.Duration = ToDuration(source.Duration, project);
target.ActualDuration = ToDuration(source.ActualDuration, project);
target.RemainingDuration = ToDuration(source.RemainingDuration, project);
target.ActualWork = ToDuration(source.ActualWork, project);
target.RegularWork = ToDuration(source.RegularWork, project);
target.Work = ToDuration(source.Work, project);

Is it correct?
When profiling performance we can see the most of the time (>70%) are spent in target.Finish and target.ConstraintDate setters.

Could you explain the purpose of these lines ?

The bad performance is due to that fact that each setter of task’s properties triggers recalculation of dependent properties, according to a logic which can be observed in Microsoft Project.

For large files you can turn off recalculation using CalculationMode.None:

targetProject.CalculationMode = CalculationMode.None;
/// Create tasks

I misunderstood the CalculationMode flag. After turning off the recalculation it works really fast. Thank you.

1 Like