unyt-org / datex-core-js-legacy

DATEX Core Library for JavaScript (legacy), fully implemented in TypeScript, used by the UIX Framework
https://unyt.org
3 stars 0 forks source link

Storage memory management #58

Closed benStre closed 10 months ago

benStre commented 10 months ago

Closes https://github.com/unyt-org/datex-core-js-legacy/issues/53

This PR implements a garbage collection system for the DATEX pointer storage. This is a completely separate GC system from the runtime GC, and it is still a quite naive implementation, but it is essential for storage memory management.

The GC is not specific for a storage location, but works with all storage locations (Databases, local storage, indexed db) that implement the StorageLocation API. It works simultaneously across all storage locations.

Background: When we assume that all eternal pointers exist for "eternity", we don't need any kind of automatic storage management - pointers are added to the storage and updated, but never deleted. Before this PR, a developer could explicitly delete pointers from the storage, but they were not removed when they were no longer needed. This is a big problem for huge collections like maps and sets with lots of volatile, changing data (e.g. temporary log entries).

The basic idea for the new storage GC is to use a basic reference counting (RC) system.

Addtional new features:

Initial storage allocations when running Datex.Storage.printSnapshot() in a new UIX base project: image

benStre commented 10 months ago

@jonasstrehle this is a very essential part of the DATEX runtime - it would be great if you could also test it out with some eternal value examples in a UIX base project (Datex.Storage.printSnapshot() for verification) - and also make sure this change does not break any existing projects (the probability is very low)