Skip to content
This repository was archived by the owner on Nov 25, 2019. It is now read-only.
This repository was archived by the owner on Nov 25, 2019. It is now read-only.

Remove closures #62

@david-rhodes

Description

@david-rhodes

From Map.cs:

foreach (CanonicalTileId id in cover)
{
	var tile = new T();

	Tile.Parameters param;
	param.Id = id;
	param.MapId = this.mapId;
	param.Fs = this.fs;

        // this is a closure!
	tile.Initialize(param, () => { this.NotifyNext(tile); });

	this.tiles.Add(tile);
	this.NotifyNext(tile);
}

As noted from the Unity documentation:

Currently, inspection of code generated by IL2CPP reveals that the simple declaration and assignment of a variable of type System.Function allocates a new object. This is true whether the variable is explicit (declared in a method/class) or implicit (declared as an argument to another method).

As such, any use of anonymous methods under the IL2CPP scripting backend allocates managed memory. This is not the case under the Mono scripting backend.

Furthermore, IL2CPP displays dramatically different levels of managed memory allocation depending on the way in which a method argument is declared. Closures, as expected, allocate the most memory per call.

Unintuitively, predefined methods allocate nearly as much memory as closures when passed as arguments under the IL2CPP scripting backend. Anonymous methods generate the least amount of transient garbage on the heap, by one or more orders of magnitude.

This would require us to remove Action as method arguments. Prefer C# events?

/cc @brnkhy @isiyu @BergWerkGIS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions