Skip to content

Don't store pointers in the ABM #757

@dabele

Description

@dabele

Motivation / Current Behaviour

Storing pointers to persons and locations in the ABM is convenient for programming, since it reduces the number of function arguments. But storing indices and only passing the actual objects when needed is much more flexible. Apart from performance improvements, it would also enable e.g. copying the World.

Two major performance problems that are caused by storing pointers:

  • Adding and removing persons during migration is expensive and requires a mutex for multithreading
  • iterating is slower because of reduced locality.

Enhancement description

Persons don't store a pointer to locations. Instead they store an index, the location object is passed by the World as a function argument when necessary.

Locations don't store persons at all. When some accumulation of persons per Location is necessary, this should be done by iterating over all persons and caching the result. This requires less synchronization. (It might become necessary later for the locations to store indices to its persons. This can be added later.)

The world can store the locations and persons directly and doesn't need unique_ptr.

Additional context

No response

Checklist

  • Attached labels, especially loc:: or model:: labels.
  • Linked to project

Metadata

Metadata

Assignees

Labels

class::improvementCleanup that doesn't affect functionalityclass::performancePerformance related issuesloc::backendThis issue concerns the C++ backend implementation.model::abmThis issue concerns any kind of agent-based model.prio::highThe priority of this task is high.status::in reviewThis issues is in review.

Type

No type

Projects

Status

Done (Total) 💯

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions