performance - Deep Cloning of Java objects (Not beans) -


the project working on has lot of objects serialized in order deep copy of the existing object. works fine until have multiple calls @ runtime in cased have 100, 200, or 1000 calls between components , hit performance headache.

historical reason copying these objects being cloned , 2 different component working on same objects under different functionality should not change each other e.g. changes in swing ui should not change object values in backend until save or synchronized button pressed.

we have quite large code base, thought if write clone based on reflection work faster compared serialization , either due our complex hierarchies of objects or due other reason , approach slower.

i tried using cloneutils (sourceforge project) , slower (we not using hibernate @ all). spring beanutils not option (i assume docs uses beans i.e. introspection , in case use if fields exposed using non standard accessor , not able copy those).

has idea , improve performance while still working on different copies. have option speed things in case provide our own copy methods ,instead of serialization, has downside of updating these methods every time , if forget might loose functionality.

you can avoid reflection dynamic class generation, e.g., using cglib. each class use, you'd generate "cloner class" containing code needed copy. make reflection unnecessary, provided fields @ least package-private , put copier class in same package. you'd need default ctor , no final fields, too.

here, serialization has advantage, creates objects using sun.misc.unsafe.

implementing deepclone method in each class option, too. combined cloner-class idea.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -