dfinity / motoko

Simple high-level language for writing Internet Computer canisters
Apache License 2.0
505 stars 97 forks source link

Motoko Data Inspection #4705

Open luc-blaeser opened 1 week ago

luc-blaeser commented 1 week ago

Motoko Data Inspection

Note: This is still a prototype, not yet ready for merging.

Generic data inspection of Motoko canisters by authorized users.

Your Motoko Program is a Database!

This is only a small first step towards the bigger vision of providing data tooling to Motoko, similar to a database management system. This would support data inspection, data queries, maybe even data modification, data backup/restore, complex data migration, and/or administrative functionality.

Frontend Prototype

A simple frontend is available to test the data inspection, see https://github.com/luc-blaeser/data-inspector (limited access).

Backend Design

The Motoko runtime system is extended to stream the heap state to the frontend canister for displaying the data to authorized users.

Currently, the following design aspects apply to the data inspection in the Motoko runtime system:

Binary format (EBNF)

Format = Version Root Heap.
Version = `1: usize`.
Root = `object_id: usize`.
Heap = `object_id: usize` `object_tag: usize` `object_payload:

The object payload is organized as follows:

object_id are potentially synthetic identifiers of an objects. The ids are skewed, to distinguish them from scalars. Currently, the object_id are heap pointers but this would change with incremental inspection.

usize is 64-bit little endian.

Implementation

Future: Incremental Inspection

Incremental inspection can be realized in the future for scalability to larger heaps:

Possible implementation:

github-actions[bot] commented 1 week ago

Comparing from 247aa056afe9d5499f9f79d78d6d38117b8478ae to 53bcc7514dd2f85154196f2c79aa1d89c7cec3c3: In terms of gas, 3 tests regressed and the mean change is +0.0%. In terms of size, 5 tests regressed and the mean change is +0.4%.

crusso commented 1 week ago

Very cool!

crusso commented 1 week ago

I wonder if leb encodings would compress stuff quite a bit...