Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The following changes are proposed:

  • Field lengths are replaced with relative offsets;
  • FIeld IDs and lengths offsets are moved to object footer.;
  • Relative footer offset is added to object header.;
  • All field IDs are hashed in order they are written. Resulting value is saved to object header. We refer to is as schema ID.

...

  • Schema ID which is a hash of all field IDs. E.g. ID =  HASH("C" + HASH("B" + HASH("A")));
  • Total fields count;
  • (string, fieldId) pairsOrdered collection of field IDs.

Known schemas are stored in read-only structure. If new schema is detected during read or write, it is updated atomically. Normally object will have only 1 schema, 2-3 schemas in rare cases, >3 schemas in very rare cases. For this reason we can store them in volatile array or so.

...

  • Check if object's schema is known. Normally this will require only 1-2 int comparisons. If no, we scan the whole object, create the schema and save it.
  • Until object read schema matches object write schema, we just read the object sequentially. Schema matching is performed using reference string equality as field names are usually interned literals. In case of failed comparison we fallback to normal "String.equals()"trivial int field ID comparisons.
  • If read/write schemas mismatch is detected, we fallback to random field read. Normally mismatch will only occur if different object versions co-exist in runtime. 

...