Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve redundant references #2

Open
izackp opened this issue Jan 22, 2019 · 0 comments
Open

Resolve redundant references #2

izackp opened this issue Jan 22, 2019 · 0 comments

Comments

@izackp
Copy link
Owner

izackp commented Jan 22, 2019

Lets say you have a list of all the students in a school.
Lots of these students will have the same teacher.
If we serialize the student list and they all have the same teacher reference.. It would make sense to avoid being redundant. However, currently we just write directly to the buffer from front to back. Making some sort of 'reuse' list in the front would require making a new buffer.

We have a few options:
Keep a list of all created instances, and have a specific class 'SerializationReference' that holds an index to this cache of reference that will be resolved on deserialization. What's going to be slow is that we're going to have to 'hash' every single instance being serialized. Then we're going to have to perform a 'lookup' for the majority of deserializations.

Second option
Let the user handle it himself. You could create a serializable class called IdRef<T:iHasId> and each reference can hold an id. In the payload you could include a flat list of students and a flat list of teachers and resolve references as that property is accessed.

Third option
A combination of the above two. All serializable classes that implement iHasId could be 'flattened' then resolved. During deserialization we can store the first instance in typeInstanceTable[id] then check against it for all future instances.

Still thinking will come back to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant