Skip to main content

Module props

Module props 

Source
Expand description

The properties of nodes and of edges, which are documents (11 section 3).

A property graph is an adjacency structure and a pile of key value maps, and the second half is the part that engines get wrong. Neo4j gives every property its own store and pays a pointer chase per read. FalkorDB keeps a matrix of attribute vectors. Both are a second data model built to hold what the document model already holds, and both then need their own indexes, their own encoding and their own answer to nested values.

There is a document model here, so a node’s properties are a document and an edge’s properties are a document. That is not a saving in lines of code, it is what makes #[yo(index)] on a node’s field mean the same thing as #[yo(index)] on a document’s field, and it is why a graph gets path indexes, key interning and nested values without any of the three being written twice.

use yo_doc::Builder;
use yo_graph::Props;

let mut b = Builder::new();
b.begin_object()?;
b.key(b"name")?;
b.text("ada")?;
b.end_object()?;
let doc = b.finish()?.to_vec();

let mut people = Props::new();
people.put(41_920, &doc)?;
let got = people.get(41_920).expect("stored");
assert_eq!(got.get(b"name").and_then(|n| n.as_text()), Some("ada"));

§Interning is worth more here than anywhere else

A document collection repeats its field names on every document, which is what key interning is for. A graph repeats them harder: an edge property map is two or three fields and there are ten to a hundred times as many edges as nodes, so the names are most of what an edge property store weighs. Two byte ids against a weight and a since on fifty million edges is the difference between the properties fitting beside the adjacency and not.

§Why the id is bytes

Docs is keyed by bytes because that is what a document collection is keyed by, and a node id here is a u64, so it becomes eight bytes. They are big endian, which costs a byte swap that no lookup notices and buys the one thing byte order can buy: if this ever grows an ordered scan, the keys sort the way the numbers do.

Structs§

Props
The properties of a set of nodes, or of a set of edges.

Functions§

id_key
A node id or an edge slot, as the bytes a document collection is keyed by.