Opened 10 years ago

Last modified 10 years ago

#2416 closed task

Fix moving GC and rooting issues with ValueCloner — at Version 4

Reported by: Yves Owned by:
Priority: Should Have Milestone: Alpha 16
Component: Core engine Keywords: Spidermonkey
Cc: Patch:

Description (last modified by Yves)

The ValueCloner in ScriptInterface.cpp implements caching of cloned values by associating a GCThing pointer from another compartment with the cloned version of that value in the current compartment.

This fails with a moving GC because the GCThing pointer can change and because the jsval it uses as value in the map can also change.

There's some more information about moving GC in #2415.

Proposed solution 1

At the moment I don't see why we even need this ValueCloner. I've replaced it with a much simpler implementation with structured clones. ValueCloner was probably introduced earlier when structured clones weren't available yet or when there were some issues with them.

This solution should work with a moving GC and doesn't require special care for rooting (CloneValueFromOtherContext still returns a jsval in this patch, but that should be easy to fix later). CloneValueFromOtherContext is currently mainly used for getting data from the simulation to the GUI. There's another use of it for the serialization test mode in Simulation2.cpp.

Of course when talking about removing something that does caching, the first concern is performance. Since a new instance of ValueCloner is created for each call to CloneValueFromOtherContext, it only caches objects that are linked multiple times in the value to clone. The structured clone most likely does this too internally (otherwise it would get problems with cyclic references).

I've tested it in practice by profiling a game against the AI on Alpine Valleys. Because this cloning is mainly used in the GUI, I couldn't use a non-visual replay. This means the graphs are from different games.

Original:
Profiling original

Patch:
Profiling after applying the patch

Change History (7)

by Yves, 10 years ago

Removes ValueCloner and replaces it with a much simple implementation using StructuredClones

by Yves, 10 years ago

Profiling after applying the patch

by Yves, 10 years ago

Profiling original

comment:1 by Yves, 10 years ago

Description: modified (diff)

comment:2 by Yves, 10 years ago

Description: modified (diff)

comment:3 by Yves, 10 years ago

Description: modified (diff)

comment:4 by Yves, 10 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.