CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Forum has moved

New location: CSLA .NET forum


CSLA .NET Resources:
  • CSLA .NET forum
  • CSLA .NET home page
  • Clone/Serialization takes long time

    rated by 0 users
    Answered (Verified) This post has 2 verified answers | 9 Replies | 1 Follower

    Top 200 Contributor
    44 Posts
    c_manboy posted on Tue, Jul 30 2013 1:23 PM

    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

     

    Answered (Verified) Verified Answer

    Top 10 Contributor
    718 Posts
    Verified by c_manboy

    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).

    Top 10 Contributor
    2,279 Posts
    Answered (Verified) JonnyBee replied on Tue, Jul 30 2013 11:56 PM
    Verified by c_manboy

    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. 

    Jonny Bekkum, Norway CslaContrib Coordinator

    All Replies

    Top 10 Contributor
    2,279 Posts
    Suggested by JonnyBee

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

    Jonny Bekkum, Norway CslaContrib Coordinator

    Top 200 Contributor
    44 Posts

    CSLA 4.5.20, .net 4.5, WPF

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

    Top 10 Contributor
    2,279 Posts

    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.

    Jonny Bekkum, Norway CslaContrib Coordinator

    Top 50 Contributor
    139 Posts

    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

    Top 10 Contributor
    718 Posts
    Verified by c_manboy

    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).

    Top 10 Contributor
    2,279 Posts
    Answered (Verified) JonnyBee replied on Tue, Jul 30 2013 11:56 PM
    Verified by c_manboy

    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. 

    Jonny Bekkum, Norway CslaContrib Coordinator

    Top 10 Contributor
    2,279 Posts
    JonnyBee replied on Tue, Jul 30 2013 11:58 PM

    @stefanus Read this article

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

    Jonny Bekkum, Norway CslaContrib Coordinator

    Top 50 Contributor
    139 Posts

    thanks a lot jonny

    I'll read soon

    stefanus

     

    Top 200 Contributor
    44 Posts

    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.

    Page 1 of 1 (10 items) | RSS

    Copyright (c) 2006-2014 Marimer LLC. All rights reserved.
    Email admin@lhotka.net for support.
    Powered by Community Server (Non-Commercial Edition), by Telligent Systems