Clone/Serialization takes long time

Clone/Serialization takes long time

Old forum URL: forums.lhotka.net/forums/t/12097.aspx


c_manboy posted on Tuesday, July 30, 2013

Normal 0 false false false MicrosoftInternetExplorer4

I have a BLB EmployeeList which contains a child BLB HrDocumentList.  The HrDocumentList uses a separate DAL and connection than the EmployeeList.  The EmployeeList is roughly 110 Employee objects, and each Employee object has roughly 100 HrDocument objects.

 When I save changes the ViewModel class clones the EmployeeList prior to saving.  But the clone takes 8 seconds.  I made the HrDocumentList a private backing field and NonSerialized.  This resolved the performance issue, but introduced another issue elsewhere.

 I don’t fully understand the serialization process and how it all works together.  Does the separate DAL have anything to do with it?  How do I troublehsoot this issue?

    Public Shared ReadOnly HRDocumentsProperty As PropertyInfo(Of HRDocumentList) = RegisterProperty(Of HRDocumentList)(Function(c) c.HRDocuments, RelationshipTypes.Child)
    Public ReadOnly Property HRDocuments As HRDocumentList
        Get
            If Not (FieldManager.FieldExists(HRDocumentsProperty)) Then
                Dim criteria As New Criteria.HRDocumentCriteria
                criteria.And.EmployeeId.Equal(PayrollID)
                LoadProperty(HRDocumentsProperty, DataPortal.Fetch(Of HRDocumentList)(criteria))
            End If
            Return GetProperty(HRDocumentsProperty)
        End Get
    End Property
 
    'Public Shared ReadOnly HRDocumentsProperty As PropertyInfo(Of HRDocumentList) = RegisterProperty(Of HRDocumentList)(Function(c) c.HRDocuments, RelationshipTypes.PrivateField)
    '<NonSerialized>
    'Private _hrDocuments As HRDocumentList
    'Public ReadOnly Property HRDocuments As HRDocumentList
    '    Get
    '        If Not (FieldManager.FieldExists(HRDocumentsProperty)) Then
    '            Dim criteria As New Criteria.HRDocumentCriteria
    '            criteria.And.EmployeeId.Equal(PayrollID)
    '            _hrDocuments = DataPortal.Fetch(Of HRDocumentList)(criteria)
    '        End If
    '        Return GetProperty(HRDocumentsProperty, _hrDocuments)
    '    End Get
    'End Property

 

JonnyBee replied on Tuesday, July 30, 2013

Maybe you could supply more informatione about your environment such as CSLA version, Client Runtime and which Serializer you use.

c_manboy replied on Tuesday, July 30, 2013

CSLA 4.5.20, .net 4.5, WPF

I'm not defining a serializer, but objects are marked <Serializable()>

JonnyBee replied on Tuesday, July 30, 2013

You may specify the formatter as CslaSerializationFormatter key in app.config/web.config. When not specified you will use the System.Runtime.Serialization.Formatters.Binary.BinaryFormatter in NET.

The BinaryFormatter should only care about the member variables - not the properties as such so it is probably related to the HrDocument. Marking the private field as NonSerialized makes the BinaryFormatter ignore and not serialize this field. 

My best recommendation is to use a memory profiler to get a view of where the time is consumed in your application.

st3fanus replied on Tuesday, July 30, 2013

Hi jonny..

I have used VS 2012 memory profiler, but I don't know where to begin.

Could you have a getting started to used that ?

 

thanks a lot

stefanus

JonnyBee replied on Tuesday, July 30, 2013

@stefanus Read this article

Beginners guide to performance profiling:
http://msdn.microsoft.com/en-us/library/ms182372.aspx

st3fanus replied on Wednesday, July 31, 2013

thanks a lot jonny

I'll read soon

stefanus

 

skagen00 replied on Tuesday, July 30, 2013

Frankly, cloning is slow.  Cloning -what- 10k objects is asking for trouble (unless I am misunderstanding things).

There was a certain part of functionality a colleague developed that involved a clone and it basically ended up being 80% of the overall time a complex process took to execute.

The clone made things 5X as slow.  Maybe with the new serializer things are radically different - I'm just speaking from prior experience.

I don't know your application but generally speaking you should not be cloning an object graph of 10k items.

*Minimally* do some manual handling, only cloning items that are dirty and replacing them as necessary back to the object graph if you need to.  I'm sure there are alternative means to your solution other than cloning all 10k items (when likely only a few were changed).

JonnyBee replied on Tuesday, July 30, 2013

Or even reconsider your object graph and do NOT load that much data into memory and allow edit. 

The BinaryFormatter use the users TEMP directory and serializes to/deserialize from disk, That does add to the time used. 

You may want to check the performance with the NetDataContract serializer (default by WCF) rather than the BinaryFormatter. 
These are he only 2 binary serializers that come with .NET. 

c_manboy replied on Wednesday, July 31, 2013

Thanks for the feedback.  I didn't think through just how many items I was loading and cloning (100 employees times 100 documents really is 10,000 items...go figure).

In my MVVM approach my model was an editable EmployeeList for master/detail.  That  made binding easy.  But i'm going to move to a readonly list for the master employee list.  This should do the trick.

Copyright (c) Marimer LLC