generic-github-user / Caesium

General-purpose AI library with NEAT-style genetic algorithm.

Home Page:https://generic-github-user.github.io/Caesium/src/versions/javascript/projects/network-visualization/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Clone networks or use immutable objects?

generic-github-user opened this issue · comments

This is a pretty important decision, as it will affect the way code for this program is written for the foreseeable future.

See #87 and #89.

Both cloning and freezing could use Object.freeze() . . . but an object that is being cloned should not be frozen in case the original object needs to be modified.

I've been trying to figure this out for three days now . . .

Maybe create a pros and cons list for each option . . .

I think for now I will keep using a mutable data structure, until the scale of the project is large enough that this requires a different solution. I'm not entirely ruling out using an immutable data structure in the future, but it seems impractical at this time.

The network objects will be deep cloned with JSON.parse(JSON.stringify()) and their methods will be added automatically.

See this comment: #87 (comment)

Looks like we will actually be using an immutable data structure . . . references within network objects being cloned are causing issues: #92

Wow, algorithms using mutable objects apparently run much faster than algorithms using immutable objects:
https://stackoverflow.com/a/41432408