elsa icon indicating copy to clipboard operation
elsa copied to clipboard

Replace recursion with loop to dive into Object Graph

Open jankotek opened this issue 8 years ago • 8 comments

Elsa uses recursion to dive into object graph. That could generate long call stack and cause StackOverflow exception. Compared to Java serialization Elsa uses less stack frames and behaves better.

It should be possible to eliminate recursion and dive into object graph with simple loop. Some data structure needs to replace call stack (trie?). It should store path traversed on graph dive. Special care needs to be taken to preserve order of objects

jankotek avatar Jun 04 '16 07:06 jankotek

Should I look onto this issue?

dasbipulkumar avatar Oct 17 '16 09:10 dasbipulkumar

It is a bit of challenge, there is bug for JVM which was open since 2005. 

Stack is used to keep list of already traversed objects and their order. So you will need some knowledge of graph traversal. 

I would be happy to post more info, if you decide to do this.

jankotek avatar Oct 17 '16 14:10 jankotek

kryo also has the same issue logged since 2013 https://github.com/EsotericSoftware/kryo/issues/103

please post more details to start with the code related to this or any other enhancements.

dasbipulkumar avatar Oct 17 '16 15:10 dasbipulkumar

Update: Current version of Elsa uses non-recursive graph traversal at serialization. Object graph is traversed in for-loop and ArrayDeque is used to keep track of nested objects. No stack is expanded I tested it on linked list with graph depth of 1e7 entries.

Deserialization still uses recursion. Fix for that needs bigger code change, but I will do that as well.

jankotek avatar Nov 17 '17 22:11 jankotek

Is there a current status for the deserialization? Because of Kryo closed the related issue with 'we won't do it', Elsa would be the only serializing application that supports deep object graphs.

reuschling avatar Jun 19 '18 10:06 reuschling

There is no solution in the entire internet that can handle large graph deserialization. It will be a good unique feature. Kryo, fst and others can't do this.

samoylenkodmitry avatar Jan 20 '21 16:01 samoylenkodmitry

This feature needed for Android 4 with small stack overflow limit. Unfortunately these devices still in use.

samoylenkodmitry avatar Jan 20 '21 16:01 samoylenkodmitry

I think latest git snapshot already handles stack less serialization. I never released it.

jankotek avatar Jan 23 '21 12:01 jankotek