Page MenuHomePhabricator

Evalulate pros and cons of an immutable data type for linear model data
Open, NormalPublic8 Story Points

Description

We do a lot of defensive copying of linear model data, and have had difficult bugs in the past due to people modifying passed-by-reference objects. Using something like Facebook's immutable-js https://github.com/salier/immutable-js might protect us against some of these issues.

Cons: Would probably require a lot of additional code, replacing our neat plain object/array APIs with method calls. May also be a performance hit doing method calls instead of simple property accesses.

Thoughts?

Event Timeline

Esanders created this task.Nov 20 2015, 8:26 PM
Esanders raised the priority of this task from to Needs Triage.
Esanders updated the task description. (Show Details)
Esanders added subscribers: Esanders, DLynch, dchan, Catrope.
Restricted Application added subscribers: StudiesWorld, Aklapper. · View Herald TranscriptNov 20 2015, 8:26 PM
Jdforrester-WMF triaged this task as Normal priority.Nov 20 2015, 8:40 PM
Jdforrester-WMF set Security to None.
Jdforrester-WMF moved this task from To Triage to Freezer on the VisualEditor board.
Jdforrester-WMF edited a custom field.

Another possibility (not necessarily better; possibly less drastic) would be to have clones of ve.dm.ElementLinearData (or whatever) that use copy-on-write semantics. (So thing2 = thing.clone() is very fast, with thing2 essentially being an "empty" reference to thing until such time as a mutator is called on either thing or thing2).

Another option I've found is to use Object.freeze (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
which works on any object type (including arrays). This causes an exception to be thrown if you try to modify the object (but only if strict mode is enabled).