xitdb 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +15 -3
- data/docs/benchmarks.md +4 -1
- data/docs/core.md +15 -2
- data/docs/learning.md +211 -0
- data/docs/native-profile-performance.md +254 -0
- data/docs/ruby-profile-v1.md +2 -0
- data/docs/ruby-profile-v2.md +279 -0
- data/docs/ruby-profile-v3.md +53 -0
- data/docs/ruby-profile-v4.md +67 -0
- data/docs/ruby.md +26 -3
- data/examples/indexed_users.rb +3 -0
- data/examples/portable.rb +3 -0
- data/examples/ruby.rb +2 -0
- data/lib/xitdb/collection_declaration.rb +39 -0
- data/lib/xitdb/context.rb +154 -8
- data/lib/xitdb/conversion/byte_source.rb +112 -0
- data/lib/xitdb/conversion.rb +35 -73
- data/lib/xitdb/core/array_builder.rb +74 -0
- data/lib/xitdb/core/array_list.rb +92 -8
- data/lib/xitdb/core/b_tree.rb +127 -19
- data/lib/xitdb/core/byte_value.rb +33 -0
- data/lib/xitdb/core/bytes/source.rb +59 -0
- data/lib/xitdb/core/bytes.rb +54 -58
- data/lib/xitdb/core/compaction.rb +49 -7
- data/lib/xitdb/core/crc64.rb +8 -1
- data/lib/xitdb/core/cursor.rb +108 -18
- data/lib/xitdb/core/database.rb +163 -29
- data/lib/xitdb/core/file_store.rb +43 -1
- data/lib/xitdb/core/format.rb +39 -98
- data/lib/xitdb/core/hash_map.rb +119 -17
- data/lib/xitdb/core/hasher.rb +33 -2
- data/lib/xitdb/core/header.rb +98 -0
- data/lib/xitdb/core/linked_array_list.rb +70 -1
- data/lib/xitdb/core/memory_store.rb +23 -224
- data/lib/xitdb/core/offset_map.rb +22 -1
- data/lib/xitdb/core/record.rb +64 -0
- data/lib/xitdb/core/replication.rb +108 -25
- data/lib/xitdb/core/slot.rb +123 -0
- data/lib/xitdb/core/sorted_map/tree.rb +317 -0
- data/lib/xitdb/core/sorted_map.rb +78 -256
- data/lib/xitdb/core/store.rb +286 -0
- data/lib/xitdb/core/transaction.rb +84 -6
- data/lib/xitdb/core.rb +12 -0
- data/lib/xitdb/database.rb +194 -15
- data/lib/xitdb/declarations.rb +33 -33
- data/lib/xitdb/errors.rb +15 -0
- data/lib/xitdb/history.rb +21 -0
- data/lib/xitdb/input_guard.rb +15 -1
- data/lib/xitdb/profiles/portable/adapter.rb +380 -0
- data/lib/xitdb/profiles/portable.rb +129 -243
- data/lib/xitdb/profiles/ruby.rb +206 -24
- data/lib/xitdb/revision.rb +17 -0
- data/lib/xitdb/ruby/codec.rb +61 -54
- data/lib/xitdb/ruby/codec_registry.rb +79 -0
- data/lib/xitdb/ruby/containers.rb +355 -82
- data/lib/xitdb/ruby/encoded_value.rb +38 -0
- data/lib/xitdb/ruby/indexed_page_decoder.rb +72 -0
- data/lib/xitdb/ruby/indexed_page_encoder.rb +58 -0
- data/lib/xitdb/ruby/input.rb +55 -0
- data/lib/xitdb/ruby/key_encoding.rb +43 -5
- data/lib/xitdb/ruby/ordered_keys.rb +46 -3
- data/lib/xitdb/ruby/packed_array.rb +179 -0
- data/lib/xitdb/ruby/packed_map.rb +272 -0
- data/lib/xitdb/ruby/packing_state.rb +84 -0
- data/lib/xitdb/ruby/page_array.rb +218 -0
- data/lib/xitdb/ruby/page_cell.rb +20 -0
- data/lib/xitdb/ruby/page_codec.rb +46 -0
- data/lib/xitdb/ruby/page_decoder.rb +172 -0
- data/lib/xitdb/ruby/page_draft.rb +24 -0
- data/lib/xitdb/ruby/page_encoder.rb +149 -0
- data/lib/xitdb/ruby/page_reference.rb +26 -0
- data/lib/xitdb/ruby/page_row.rb +108 -0
- data/lib/xitdb/ruby/pages.rb +94 -0
- data/lib/xitdb/ruby/scalars.rb +175 -33
- data/lib/xitdb/ruby/wire/reader.rb +138 -0
- data/lib/xitdb/ruby/wire.rb +36 -90
- data/lib/xitdb/ruby.rb +43 -3
- data/lib/xitdb/snapshot.rb +8 -0
- data/lib/xitdb/streams/handle.rb +46 -0
- data/lib/xitdb/streams/reader.rb +122 -0
- data/lib/xitdb/streams/writer.rb +43 -0
- data/lib/xitdb/streams.rb +8 -140
- data/lib/xitdb/uint.rb +17 -0
- data/lib/xitdb/value_walker.rb +86 -16
- data/lib/xitdb/version.rb +2 -1
- data/lib/xitdb/views/array.rb +94 -74
- data/lib/xitdb/views/base.rb +144 -12
- data/lib/xitdb/views/linked_array.rb +7 -1
- data/lib/xitdb/views/map.rb +71 -3
- data/lib/xitdb/views/set.rb +13 -1
- data/lib/xitdb/views/slice.rb +101 -0
- data/lib/xitdb/views/sorted.rb +25 -37
- data/lib/xitdb/views/sorted_map.rb +39 -0
- data/lib/xitdb/views/sorted_set.rb +10 -0
- data/lib/xitdb.rb +3 -0
- data/sig/core.rbs +65 -34
- data/sig/public.rbs +24 -19
- data/sig/ruby.rbs +260 -42
- metadata +42 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 50edbd15d3a1c771dfae1506411190aba518bbbab14f8f53a1a402076085ed04
|
|
4
|
+
data.tar.gz: 12f886e8d0053df2cb255fda3c5477f9376da306aa9ce987fbc86e56212651ab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f1a0c57f40c1c940537fa150051d2f0f972693de23e0414de6a0ffb9b59b98561f61110d9b68584daa5ff1838bf84a09547802fd388ebbe078b29f368d0df8d1
|
|
7
|
+
data.tar.gz: '087f348e9a57fa64f71b0fd27be30843dffdccc9e358ab5e89584c453f241f8f752f37ad3516882bef947db117c87b7e0d855071e40bc2aac9a15c5592159a6e'
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.2.0 - 2026-11-18
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- New files use upstream format version 2 to fix tearing caused by the unaligned version 1 size field. Version 1 files remain readable and writable.
|
|
10
|
+
- Use `format_version: 1` when creating or compacting a portable file for a version 1 reader.
|
|
11
|
+
- Use `db.header.committed_size_offset` and `db.header.data_offset` for format-specific offsets. These replace the fixed Core database offsets.
|
|
12
|
+
- Breaking: Native files use `rb04` with compact ordered records, shared field dictionaries, and indexed row pages. Ruby handles reject `rb01`, `rb02`, and `rb03` files. Export data with its matching version before upgrading.
|
|
13
|
+
- Native String, Symbol, and codec payloads append in bounded chunks without joining complete encoded payloads. Scalar wire bytes remain unchanged.
|
|
14
|
+
- Pinned references retain portable graphs and opaque Ruby scalar maintenance. Native containers require the Core record extension and are incompatible with those references.
|
|
15
|
+
|
|
16
|
+
- Core boolean readers are now `Slot#full?` and `Cursor#valid?`; the old names were removed.
|
|
17
|
+
- Validation and assertion helpers now use `!`, including `Core::Format.integer!` and `Core::Format.ensure_width!`.
|
|
18
|
+
- Substantial classes have dedicated files. Existing require entry points still work.
|
|
19
|
+
- The interoperability workflow uses Zig 0.17.1.
|
|
20
|
+
|
|
5
21
|
## 0.1.0 - 2026-11-05
|
|
6
22
|
|
|
7
23
|
Initial release of the `xitdb` gem. Requires MRI 3.3 or later.
|
data/README.md
CHANGED
|
@@ -58,7 +58,7 @@ end
|
|
|
58
58
|
| Entry point | Values and keys | File identifier |
|
|
59
59
|
| --- | --- | --- |
|
|
60
60
|
| `XitDB.open`, `XitDB.memory` | Portable integers, floats, bytes, collections, and String keys | `sha1` by default; `hash: :sha256` selects `sha2` |
|
|
61
|
-
| `XitDB::Ruby.open`, `XitDB::Ruby.memory` | Ruby scalar values, typed keys, and ordered maps and sets | `
|
|
61
|
+
| `XitDB::Ruby.open`, `XitDB::Ruby.memory` | Ruby scalar values, typed keys, and ordered maps and sets | `rb04` |
|
|
62
62
|
| `XitDB::Core::Database` | Raw slots, every upstream collection, and arbitrary roots | Explicit storage configuration |
|
|
63
63
|
|
|
64
64
|
Opening never converts a profile. Public entry points reject a mismatched profile and pre-existing zero-byte files.
|
|
@@ -78,13 +78,20 @@ Portable maps and sets require String keys or members; portable values exclude b
|
|
|
78
78
|
The Ruby profile supports these types and preserves insertion order in ordinary maps and sets.
|
|
79
79
|
Profile conversion is explicit. Conversion can duplicate shared data across histories; see [measurements and costs](docs/benchmarks.md).
|
|
80
80
|
|
|
81
|
+
New files use xitdb format version 2 to fix tearing caused by the unaligned version 1 size field. Version 1 files remain readable and writable.
|
|
82
|
+
Pass `format_version: 1` to `XitDB.open` when creating a portable file for a version 1 reader.
|
|
83
|
+
To upgrade an existing file and keep its latest state, use `db.compact(to: "upgraded.xit")`.
|
|
84
|
+
|
|
81
85
|
Version 0.1.0 is the initial release. The public API can change before 1.0.
|
|
82
86
|
|
|
83
87
|
## Documentation
|
|
84
88
|
|
|
89
|
+
Start with [Learn xitdb](docs/learning.md) for a beginner's explanation of values, transactions, snapshots, profiles, and storage.
|
|
90
|
+
Ruby source includes YARD API comments. With YARD available, run `yard doc` and open `doc/index.html`.
|
|
91
|
+
|
|
85
92
|
Read the [portable guide](docs/portable.md), [Ruby guide](docs/ruby.md), and [core guide](docs/core.md).
|
|
86
|
-
The [Ruby wire contract](docs/ruby-profile-
|
|
87
|
-
|
|
93
|
+
The [Ruby wire contract](docs/ruby-profile-v4.md) defines compact native containers, indexed row pages, and exact scalar payloads.
|
|
94
|
+
Pinned references preserve opaque Ruby scalar bytes inside portable containers. Native `rb04` containers require the Core record extension.
|
|
88
95
|
|
|
89
96
|
## Run the workflows
|
|
90
97
|
|
|
@@ -98,6 +105,11 @@ From a checkout, run them with `bundle exec ruby -Ilib examples/portable.rb`, su
|
|
|
98
105
|
## Verify a checkout
|
|
99
106
|
|
|
100
107
|
Run `bundle install` to install the locked development dependencies.
|
|
108
|
+
|
|
109
|
+
Load `xitdb/ruby` directly from the checkout with `ruby -Ilib`. Run `bundle exec rake` for the complete quality gate.
|
|
110
|
+
|
|
111
|
+
The Linux memory gate uses the cached `ruby:4.0.9` image. It copies the Ruby sources into an isolated runtime before starting the measured container. Both containers run without network access.
|
|
112
|
+
|
|
101
113
|
Run `bundle exec ruby script/ci.rb` to check the checkout.
|
|
102
114
|
It checks Ruby style, library types, and Change Risk Anti-Patterns (CRAP), then inspects the locally built package.
|
|
103
115
|
The tests execute packaged examples from temporary storage and inspect package contents.
|
data/docs/benchmarks.md
CHANGED
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
The stress command measures file databases inside an isolated Linux container with a hard memory budget.
|
|
4
4
|
The benchmark command measures fixed workloads without timing pass thresholds.
|
|
5
|
-
Both commands require Docker and the cached `ruby:4.0.9
|
|
5
|
+
Both commands require Docker and the cached `ruby:4.0.9` image. A separate container prepares a runtime by copying Ruby sources before memory measurement.
|
|
6
6
|
They use `--pull=never` and `--network=none` and fail when the required capability is unavailable.
|
|
7
7
|
They install nothing.
|
|
8
8
|
|
|
9
|
+
The separate [native Ruby record comparison](native-profile-performance.md) measures construction, reads, updates, history growth, and compaction against a fixed baseline revision.
|
|
10
|
+
It runs directly on the host and includes portable and JSON controls.
|
|
11
|
+
|
|
9
12
|
## Run the workloads
|
|
10
13
|
|
|
11
14
|
1. Run `ruby script/stress.rb --limit-mib 256 --data-mib 768`.
|
data/docs/core.md
CHANGED
|
@@ -110,14 +110,27 @@ Library errors inherit `XitDB::Error`; standard argument, missing-key, index, an
|
|
|
110
110
|
|
|
111
111
|
## Physical contract
|
|
112
112
|
|
|
113
|
-
The header occupies 20 bytes.
|
|
113
|
+
The immutable database header occupies 20 bytes.
|
|
114
|
+
In version 2, four padding bytes precede the eight-byte committed size at offset 24.
|
|
115
|
+
A commit requests an aligned eight-byte write. A short write can still expose a partial size before the retry.
|
|
116
|
+
In version 1, the root header contains a nine-byte cached slot and the eight-byte committed size at offset 29.
|
|
117
|
+
A version 1 file can still have a torn header read during a concurrent commit. The trailer supplies the root in both versions.
|
|
114
118
|
A trailer contains a root slot, commit identifier, and CRC-64/XZ checksum, occupying 25 bytes.
|
|
115
|
-
An initialized empty database occupies
|
|
119
|
+
An initialized empty database occupies 57 bytes in version 2 or 62 bytes in version 1.
|
|
120
|
+
Parsing checks object ranges against committed boundaries before allocating.
|
|
121
|
+
Use `db.header.committed_size_offset` and `db.header.data_offset` for version-specific offsets.
|
|
116
122
|
Graph traversal uses an explicit stack. Write buffers are bounded at 2 MiB, byte transfers at 64 KiB, and offset caches spill after 16,384 entries.
|
|
117
123
|
|
|
118
124
|
`XitDB::Core::Bytes` owns physical byte storage, including inline selection, lengths, format tags, and bounded transfers.
|
|
119
125
|
Scalar materialization, streams, conversion, and compaction use that implementation. Profiles retain payload interpretation and encoding rules.
|
|
120
126
|
Compaction preserves external byte records, including short payloads and unknown format tags.
|
|
121
127
|
|
|
128
|
+
The private `:record` extension uses tag code 17, after the upstream tags.
|
|
129
|
+
A record contains unsigned 32-bit metadata, an unsigned 32-bit field count, and consecutive nine-byte slots, all in big-endian order.
|
|
130
|
+
The field count cannot exceed 32. Readers check the count and captured boundary before loading fields.
|
|
131
|
+
Compaction reserves each record before remapping its fields, preserving sharing and cycles.
|
|
132
|
+
The enclosing logical mutation owns rollback and publication. Record construction appends complete bytes without publishing a root.
|
|
133
|
+
Portable writers do not emit this extension. Upstream implementations require extension support before maintaining graphs that contain it.
|
|
134
|
+
|
|
122
135
|
The port preserves the package's [MIT license notice](../LICENSE).
|
|
123
136
|
Reference revisions and source hashes are recorded in `test/interop/manifest.json` in the source checkout.
|
data/docs/learning.md
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# Learn xitdb
|
|
2
|
+
|
|
3
|
+
xitdb stores collections in a file. A collection holds related values: a map connects keys to values, an array uses numbered positions, and a set holds unique members.
|
|
4
|
+
|
|
5
|
+
Start with the public API. Read the storage core after you can create a database, change values, and read snapshots.
|
|
6
|
+
|
|
7
|
+
## Store your first value
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
require "xitdb"
|
|
11
|
+
|
|
12
|
+
XitDB.memory do |db|
|
|
13
|
+
db.transaction do |root|
|
|
14
|
+
root["user"] = { "name" => "Ada", "visits" => 1 }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
puts db.snapshot.dig("user", "name") # Ada
|
|
18
|
+
end
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`memory` keeps the database in this process. To keep data after the process ends, use `XitDB.open("users.xit")` with the same block.
|
|
22
|
+
|
|
23
|
+
The block form closes the database automatically. Without a block, keep the returned handle and call `close` yourself.
|
|
24
|
+
|
|
25
|
+
## Understand the root and views
|
|
26
|
+
|
|
27
|
+
The root is the top-level map. In the example, `"user"` is a root key, and its value is another map.
|
|
28
|
+
|
|
29
|
+
Reading a nested collection returns a view. A view reads stored entries when you request them. It does not load the entire collection.
|
|
30
|
+
|
|
31
|
+
Call `to_ruby` when you need ordinary Ruby containers that remain usable after the database closes:
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
require "xitdb"
|
|
35
|
+
|
|
36
|
+
data = XitDB.memory do |db|
|
|
37
|
+
db.transaction { |root| root["names"] = ["Ada", "Lin"] }
|
|
38
|
+
db.snapshot.to_ruby
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
puts data["names"].first # Ada
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`to_ruby` reads every nested entry. Its memory cost grows with the complete result. Normal views let you read selected entries.
|
|
45
|
+
|
|
46
|
+
## Change values in a transaction
|
|
47
|
+
|
|
48
|
+
A transaction groups related changes. Normal block completion commits them together. An exception aborts them.
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
require "xitdb"
|
|
52
|
+
|
|
53
|
+
XitDB.memory do |db|
|
|
54
|
+
db.transaction { |root| root["visits"] = 1 }
|
|
55
|
+
|
|
56
|
+
begin
|
|
57
|
+
db.transaction do |root|
|
|
58
|
+
root["visits"] = 2
|
|
59
|
+
raise "cancel this change"
|
|
60
|
+
end
|
|
61
|
+
rescue RuntimeError
|
|
62
|
+
puts db.snapshot["visits"] # 1
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The writable root and its nested views belong to that transaction. They expire when its block ends. Read the returned snapshot for committed values.
|
|
68
|
+
|
|
69
|
+
Writers wait for a lock, which gives one writer access at a time. A lock timeout raises `BusyError` before the transaction block runs.
|
|
70
|
+
|
|
71
|
+
A commit error needs different handling. Read `CommitError#outcome` before deciding whether to retry. `:committed` means publication succeeded, and `:unknown` means the result could not be established.
|
|
72
|
+
|
|
73
|
+
An automatic retry can repeat application effects. See [locking and durability](https://github.com/svyatov/xitdb-ruby/blob/main/docs/core.md#locking-and-durability) for the full contract.
|
|
74
|
+
|
|
75
|
+
## Keep a previous state
|
|
76
|
+
|
|
77
|
+
A snapshot captures a committed root. Later transactions do not change its values.
|
|
78
|
+
|
|
79
|
+
```ruby
|
|
80
|
+
require "xitdb"
|
|
81
|
+
|
|
82
|
+
XitDB.memory do |db|
|
|
83
|
+
db.transaction { |root| root["score"] = 10 }
|
|
84
|
+
before = db.snapshot
|
|
85
|
+
db.transaction { |root| root["score"] = 20 }
|
|
86
|
+
|
|
87
|
+
puts before["score"] # 10
|
|
88
|
+
puts db.snapshot["score"] # 20
|
|
89
|
+
|
|
90
|
+
db.revert(before)
|
|
91
|
+
puts db.snapshot["score"] # 10
|
|
92
|
+
puts db.history.size # 3
|
|
93
|
+
end
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`revert` adds a commit containing the selected previous state. It preserves the commits already in history.
|
|
97
|
+
|
|
98
|
+
Snapshots remain usable until their database handle closes. A revision is a token that identifies a history entry and checks its file generation.
|
|
99
|
+
|
|
100
|
+
An array range returns a captured, read-only slice. Use the original writable array view to change entries.
|
|
101
|
+
|
|
102
|
+
## Choose how values are represented
|
|
103
|
+
|
|
104
|
+
A profile defines which values and keys a file supports. It also defines how stored bytes become Ruby values.
|
|
105
|
+
|
|
106
|
+
| Profile | Entry point | Use it for |
|
|
107
|
+
| --- | --- | --- |
|
|
108
|
+
| Portable | `require "xitdb"`, `XitDB.open` | String keys and values supported by upstream implementations |
|
|
109
|
+
| Ruby | `require "xitdb/ruby"`, `XitDB::Ruby.open` | Symbol keys, booleans, large integers, dates, and other Ruby values |
|
|
110
|
+
|
|
111
|
+
```ruby
|
|
112
|
+
require "xitdb/ruby"
|
|
113
|
+
|
|
114
|
+
XitDB::Ruby.memory do |db|
|
|
115
|
+
db.transaction do |root|
|
|
116
|
+
root[:enabled] = true
|
|
117
|
+
root[:large] = 2**200
|
|
118
|
+
end
|
|
119
|
+
puts db.snapshot[:enabled] # true
|
|
120
|
+
end
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Opening a file does not change its profile. Use `Database#convert` to copy values into a different profile.
|
|
124
|
+
|
|
125
|
+
A codec converts an application object to a supported payload and converts that payload back. Register matching codecs when reading custom values.
|
|
126
|
+
|
|
127
|
+
The [Ruby guide](https://github.com/svyatov/xitdb-ruby/blob/main/docs/ruby.md) explains codec registration and the supported value types. The [portable guide](https://github.com/svyatov/xitdb-ruby/blob/main/docs/portable.md) lists portable values and limits.
|
|
128
|
+
|
|
129
|
+
## Choose a collection
|
|
130
|
+
|
|
131
|
+
Ordinary Ruby Hashes and Arrays are enough for many assignments. Collection declarations select a specific storage layout for an empty collection.
|
|
132
|
+
|
|
133
|
+
```ruby
|
|
134
|
+
require "xitdb"
|
|
135
|
+
|
|
136
|
+
XitDB.memory do |db|
|
|
137
|
+
db.transaction do |root|
|
|
138
|
+
root["users"] = XitDB.map(counted: true)
|
|
139
|
+
root["users"]["ada"] = { "name" => "Ada" }
|
|
140
|
+
root["scores"] = XitDB.sorted_map
|
|
141
|
+
root["scores"]["ada"] = 10
|
|
142
|
+
end
|
|
143
|
+
p db.snapshot["scores"].page(offset: 0, limit: 5).to_a
|
|
144
|
+
end
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
| Collection | Meaning | Relevant API |
|
|
148
|
+
| --- | --- | --- |
|
|
149
|
+
| Map | Each unique key selects a value | `Views::Map` |
|
|
150
|
+
| Array | Each position selects a value | `Views::Array` |
|
|
151
|
+
| Linked array | An array backed by a tree for positional changes | `Views::LinkedArray` |
|
|
152
|
+
| Set | Each member appears once | `Views::Set` |
|
|
153
|
+
| Sorted map or set | Iteration follows the declared key order | `Views::Sorted` |
|
|
154
|
+
|
|
155
|
+
A counted hash collection stores its size with the structure. An uncounted hash collection can need traversal to calculate size.
|
|
156
|
+
|
|
157
|
+
Ruby-profile ordinary maps and sets preserve insertion order. Portable hash iteration follows storage order. Sorted collections follow their key ordering rules.
|
|
158
|
+
|
|
159
|
+
Adding or removing members during iteration raises `ConcurrentModificationError`. Replacing a collection can expire views of that location and its descendants.
|
|
160
|
+
|
|
161
|
+
## Understand the storage core
|
|
162
|
+
|
|
163
|
+
The public API turns Ruby values into stored structures through three layers:
|
|
164
|
+
|
|
165
|
+
1. A view provides map, array, or set operations at a logical path.
|
|
166
|
+
2. A profile encodes values and selects the correct collection adapter.
|
|
167
|
+
3. The core reads and writes slots, collection nodes, and commit records.
|
|
168
|
+
|
|
169
|
+
A slot is a small stored value descriptor. Its tag identifies the value kind. Its payload holds a small value or a reference to other bytes.
|
|
170
|
+
|
|
171
|
+
An offset is a byte position in storage. A bound is the exclusive end position that a captured reader may access.
|
|
172
|
+
|
|
173
|
+
A cursor carries a slot, its database, and its readable bound. A transaction cursor can replace its slot as structures change.
|
|
174
|
+
|
|
175
|
+
Committed structures are immutable. Changing a collection creates changed structure while keeping previous committed versions readable. Unchanged parts can share stored references.
|
|
176
|
+
|
|
177
|
+
A hash map uses a hash digest to locate a key through a tree. A sorted tree uses key comparisons to visit entries in order.
|
|
178
|
+
|
|
179
|
+
A trailer records a published root and its integrity information. A checksum detects changes to the checked bytes; it does not authenticate an untrusted file.
|
|
180
|
+
|
|
181
|
+
Compaction copies reachable structures to a separate file. Profile conversion reads logical values and encodes them again, which can duplicate shared data across history.
|
|
182
|
+
|
|
183
|
+
Replication transfers storage under the core's compatibility checks. It does not reinterpret values or convert profiles.
|
|
184
|
+
|
|
185
|
+
The [core guide](https://github.com/svyatov/xitdb-ruby/blob/main/docs/core.md) explains the file format, locking, durability, compaction, and replication.
|
|
186
|
+
|
|
187
|
+
## Find the implementation
|
|
188
|
+
|
|
189
|
+
| Path | Responsibility |
|
|
190
|
+
| --- | --- |
|
|
191
|
+
| `lib/xitdb/database.rb` | Public handle, transactions, snapshots, and maintenance |
|
|
192
|
+
| `lib/xitdb/views/` | Collection methods used by applications |
|
|
193
|
+
| `lib/xitdb/context.rb` | View lifetime, location checks, and logical mutations |
|
|
194
|
+
| `lib/xitdb/profiles/` | Portable and Ruby value interpretation |
|
|
195
|
+
| `lib/xitdb/ruby/` | Ruby scalars, keys, codecs, and container representation |
|
|
196
|
+
| `lib/xitdb/core/` | Storage, binary format, trees, commits, and replication |
|
|
197
|
+
| `lib/xitdb/value_walker.rb` | Nested value encoding and conversion to Ruby containers |
|
|
198
|
+
| `lib/xitdb/conversion.rb` | Copying logical values across contexts and profiles |
|
|
199
|
+
| `examples/` | Runnable application workflows |
|
|
200
|
+
| `test/` | Behavior checks and fault-injection helpers |
|
|
201
|
+
| `script/` | Development checks, measurements, and reference implementation checks |
|
|
202
|
+
|
|
203
|
+
Internal helpers use `@api private` where appropriate. They explain implementation details without promising a stable application API.
|
|
204
|
+
|
|
205
|
+
## Build the API reference
|
|
206
|
+
|
|
207
|
+
With YARD available in your development environment, run `yard doc` from the repository root. Open `doc/index.html` to read the result.
|
|
208
|
+
|
|
209
|
+
`.yardopts` selects library source and includes this guide. Run `yard stats --list-undoc` to inspect documentation coverage.
|
|
210
|
+
|
|
211
|
+
YARD is optional and is not a runtime dependency. The generated `doc/` and `.yardoc/` directories are ignored by Git.
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
# Native Ruby storage performance
|
|
2
|
+
|
|
3
|
+
The packed native profile uses `rb02`. Small maps, sets, and arrays have bounded records with ordered slots. Large arrays retain an indexed tree built from completed blocks. Field dictionaries and short scalar values share storage within bounded encoding operations.
|
|
4
|
+
|
|
5
|
+
For 10,000 records in a file, median insert falls from 59.75 to 3.72 seconds and full read from 18.50 to 0.790 seconds against optimized rb01. Compacted storage falls from 26,821,960 to 1,106,827 bytes, a 95.9% reduction. All six native dataset/store cases improve substantially in both bulk operations and retained storage.
|
|
6
|
+
|
|
7
|
+
This intentionally replaces `rb01`. Existing rb01 native files cannot be opened by this profile. No migration or backward reader is included. Portable files retain their wire format.
|
|
8
|
+
|
|
9
|
+
## Workload and method
|
|
10
|
+
|
|
11
|
+
The source fixture is the separate, unchanged crap4ruby checkout. Sorted `lib/**/*.rb` files are analyzed with `Crap4Ruby::Analyzer.new.call(File.binread(path), path: path)`. Each method produces the six ordered fields specified in the task: name, namespace, path, complexity, coverage, and crap.
|
|
12
|
+
|
|
13
|
+
The fixture contains 58 records. Its JSON representation is 7,696 bytes, with SHA-256 `d975d573ec71a8b2ae214d47f1092d0ecf658c1243861449f437c30e74f3d081`. The digest of `Marshal.dump(records)` is `788ae8b9c6339262b24d51d020b97f9cfac67e5e5e73f36330348635a836321e`. Workers receive an owned Marshal fixture file to preserve String encodings. Raw artifacts contain the fixture revision and every input file hash.
|
|
14
|
+
|
|
15
|
+
Deterministic 1,000- and 10,000-record datasets use six fields, unique method names, seventeen namespaces, eleven paths, twenty complexity values, and two nil fields. They measure repeated record shapes and short repeated values. Results do not establish equivalent gains for unrelated shapes, large maps, or long unique values.
|
|
16
|
+
|
|
17
|
+
Each comparison has eighteen cases: three datasets, memory and file stores, and native, portable, and portable JSON layouts. Every case has one excluded warmup pair and seven measured pairs. Revision order alternates within each case. Workers run serially in fresh processes, with library loading measured separately. Both library revisions are extracted from Git before measurement.
|
|
18
|
+
|
|
19
|
+
The read operation materializes the complete result and checks equality. An untimed correctness read precedes the timed read on the original handle. Native reads also check key order and String encodings. Indexed operations read rows at the start, middle, and end. Reopened indexed reads precede full reads on the reopened handle. These are warm OS-cache measurements, not cold-disk tests. JSON operations include encoding for writes and decoding for reads and updates.
|
|
20
|
+
|
|
21
|
+
An identical reassignment is a second complete assignment in a transaction. A nested update changes the middle row's complexity. Ten further commits change a root revision field. Earlier snapshots must remain equal to the original input. Compaction retains the latest history, which must still match the updated input. File stores are also reopened after all writes.
|
|
22
|
+
|
|
23
|
+
Timing uses a monotonic clock. Allocation counts use `GC.stat(:total_allocated_objects)`, with a full collection before each timed operation. OS caches are not flushed. Elapsed times include normal transaction flush behavior; they do not imply a new durability setting. Instrumented CPU and byte-traffic probes run separately from the timing matrix.
|
|
24
|
+
|
|
25
|
+
The matrix uses Ruby 4.0.9, revision `3e93b23afc`, with PRISM on `arm64-darwin25`. The checkout continues to report gem version 0.1.0. CPU-model and physical-RAM queries through `sysctl` were denied by the sandbox, so those hardware details are unavailable.
|
|
26
|
+
|
|
27
|
+
The fresh comparison uses optimized rb01 revision `fde9a5dda601643398289f5bd0ebfdbfa7f2089e` and packed revision `af53aeb834e396eddfd2e077798d0ec614eb066f`. Original baseline revision `89f714d8de855cb9fdd31eb3f9e5e8d666cd8bef` is measured in the separately archived historical comparison. Its interrupted run was preserved before packing experiments; missing samples are resumed with its exact archived worker and matching library hashes. Historical and fresh timings must not be treated as one simultaneous paired run.
|
|
28
|
+
|
|
29
|
+
## Results
|
|
30
|
+
|
|
31
|
+
The following fresh native comparisons have seven measured samples per revision and an excluded warmup pair. Cells show optimized rb01 / packed rb02, followed by the ratio of unrounded medians. Bulk-operation times are seconds.
|
|
32
|
+
|
|
33
|
+
| Records | Store | Insert | Full read | Reassign | Compact |
|
|
34
|
+
|---:|---|---:|---:|---:|---:|
|
|
35
|
+
| 58 | memory | 0.213 / 0.024 (8.9x) | 0.072 / 0.003 (21.8x) | 0.208 / 0.022 (9.4x) | 0.052 / 0.005 (10.1x) |
|
|
36
|
+
| 58 | file | 0.244 / 0.025 (9.9x) | 0.105 / 0.005 (22.4x) | 0.243 / 0.024 (10.1x) | 0.073 / 0.006 (11.7x) |
|
|
37
|
+
| 1,000 | memory | 3.884 / 0.359 (10.8x) | 1.221 / 0.054 (22.7x) | 3.900 / 0.356 (10.9x) | 7.040 / 0.058 (121.3x) |
|
|
38
|
+
| 1,000 | file | 4.694 / 0.369 (12.7x) | 1.778 / 0.075 (23.8x) | 4.567 / 0.370 (12.3x) | 7.316 / 0.084 (86.6x) |
|
|
39
|
+
| 10,000 | memory | 52.145 / 3.581 (14.6x) | 12.274 / 0.550 (22.3x) | 52.902 / 3.647 (14.5x) | 96.246 / 2.975 (32.3x) |
|
|
40
|
+
| 10,000 | file | 59.749 / 3.724 (16.0x) | 18.499 / 0.790 (23.4x) | 59.357 / 3.774 (15.7x) | 95.052 / 3.293 (28.9x) |
|
|
41
|
+
|
|
42
|
+
Selective-operation times below are milliseconds. Indexed reads select three complete rows.
|
|
43
|
+
|
|
44
|
+
| Records | Store | Three indexed reads | Nested update | Ten commits |
|
|
45
|
+
|---:|---|---:|---:|---:|
|
|
46
|
+
| 58 | memory | 7.664 / 2.176 (3.5x) | 4.691 / 2.192 (2.1x) | 13.540 / 6.696 (2.0x) |
|
|
47
|
+
| 58 | file | 10.823 / 3.009 (3.6x) | 7.810 / 3.274 (2.4x) | 21.751 / 10.489 (2.1x) |
|
|
48
|
+
| 1,000 | memory | 7.529 / 2.239 (3.4x) | 4.817 / 2.253 (2.1x) | 13.426 / 6.412 (2.1x) |
|
|
49
|
+
| 1,000 | file | 10.866 / 3.130 (3.5x) | 8.103 / 3.905 (2.1x) | 21.246 / 11.494 (1.8x) |
|
|
50
|
+
| 10,000 | memory | 7.860 / 2.375 (3.3x) | 5.134 / 2.450 (2.1x) | 14.418 / 6.657 (2.2x) |
|
|
51
|
+
| 10,000 | file | 11.403 / 3.313 (3.4x) | 8.443 / 4.135 (2.0x) | 21.996 / 11.271 (2.0x) |
|
|
52
|
+
|
|
53
|
+
Reopened-file times are milliseconds. Three indexed reads precede complete materialization on each reopened handle.
|
|
54
|
+
|
|
55
|
+
| Records | Open handle | Three indexed reads | Complete read |
|
|
56
|
+
|---:|---:|---:|---:|
|
|
57
|
+
| 58 | 0.444 / 0.396 (1.1x) | 10.631 / 3.038 (3.5x) | 105.233 / 4.682 (22.5x) |
|
|
58
|
+
| 1,000 | 0.454 / 0.409 (1.1x) | 10.692 / 3.098 (3.5x) | 1,781.104 / 74.539 (23.9x) |
|
|
59
|
+
| 10,000 | 0.565 / 0.438 (1.3x) | 11.580 / 3.234 (3.6x) | 18,320.113 / 789.021 (23.2x) |
|
|
60
|
+
|
|
61
|
+
For 10,000 file-backed records, insert allocations fall from 211,126,083 to 6,321,335, and full-read allocations fall from 34,099,421 to 1,968,278. The raw matrix retains allocations for every operation and sample.
|
|
62
|
+
|
|
63
|
+
The native byte counts below are identical in memory and file stores. The latest state includes the nested update and root revision field.
|
|
64
|
+
|
|
65
|
+
| Records | Original rb01 initial | Optimized rb01 initial | Packed initial | rb01 compacted | Packed compacted | Packed retained bytes/record |
|
|
66
|
+
|---:|---:|---:|---:|---:|---:|---:|
|
|
67
|
+
| 58 | 665,247 | 292,447 | 7,865 | 158,695 | 7,910 | 136.38 |
|
|
68
|
+
| 1,000 | 11,528,267 | 5,126,667 | 111,238 | 2,682,891 | 111,283 | 111.28 |
|
|
69
|
+
| 10,000 | 116,459,112 | 52,457,512 | 1,106,782 | 26,821,960 | 1,106,827 | 110.68 |
|
|
70
|
+
|
|
71
|
+
The following packed history growth is measured in bytes. All source histories contain thirteen commits; compacted files contain one.
|
|
72
|
+
|
|
73
|
+
| Records | Identical reassignment growth | Nested update growth | Ten commits growth | Total before compaction | After compaction |
|
|
74
|
+
|---:|---:|---:|---:|---:|---:|
|
|
75
|
+
| 58 | 7,620 | 603 | 2,317 | 18,405 | 7,910 |
|
|
76
|
+
| 1,000 | 110,993 | 747 | 2,317 | 225,295 | 111,283 |
|
|
77
|
+
| 10,000 | 1,106,537 | 891 | 2,317 | 2,216,527 | 1,106,827 |
|
|
78
|
+
|
|
79
|
+
The following controls use the packed revision's library and file stores, with seven measured samples each. Times are seconds. JSON encoding and decoding are included.
|
|
80
|
+
|
|
81
|
+
| Records | Layout | Initial bytes | Compacted bytes | Insert | Full read | Three indexed reads | Nested update |
|
|
82
|
+
|---:|---|---:|---:|---:|---:|---:|---:|
|
|
83
|
+
| 58 | Native | 7,865 | 7,910 | 0.024768 | 0.004683 | 0.003009 | 0.003274 |
|
|
84
|
+
| 58 | Portable | 94,551 | 29,293 | 0.106449 | 0.007514 | 0.002024 | 0.002470 |
|
|
85
|
+
| 58 | JSON | 8,581 | 8,333 | 0.001885 | 0.000283 | 0.000256 | 0.001182 |
|
|
86
|
+
| 1,000 | Native | 111,238 | 111,283 | 0.368520 | 0.074782 | 0.003130 | 0.003905 |
|
|
87
|
+
| 1,000 | Portable | 1,729,947 | 466,225 | 1.780262 | 0.130092 | 0.002162 | 0.003095 |
|
|
88
|
+
| 1,000 | JSON | 115,826 | 115,578 | 0.002020 | 0.000712 | 0.000480 | 0.001725 |
|
|
89
|
+
| 10,000 | Native | 1,106,782 | 1,106,827 | 3.723737 | 0.790282 | 0.003313 | 0.004135 |
|
|
90
|
+
| 10,000 | Portable | 18,502,088 | 4,666,590 | 18.598426 | 1.305861 | 0.002269 | 0.003332 |
|
|
91
|
+
| 10,000 | JSON | 1,160,301 | 1,160,053 | 0.003979 | 0.005184 | 0.002768 | 0.006296 |
|
|
92
|
+
|
|
93
|
+
At 10,000 records, native storage is 4.6% smaller than the compacted JSON control. JSON remains about 936 times faster for complete insert and 152 times faster for complete read. Even its complete-payload indexed read is faster here, 2.77 ms against native's 3.31 ms. Native's selective access avoids decoding the complete payload, but does not guarantee lower latency at these sizes. Its nested update is faster and writes a bounded path instead of replacing the complete payload.
|
|
94
|
+
|
|
95
|
+
Xitdb loading is excluded from operation timings. The harness has already loaded JSON and its other standard-library reporting tools before this measurement. The table below aggregates forty-two measured Xitdb requires per revision/layout. These are medians across datasets and stores, in milliseconds; they are not complete process-startup times.
|
|
96
|
+
|
|
97
|
+
| Layout | Optimized rb01 load | Packed revision load | Optimized allocations | Packed allocations |
|
|
98
|
+
|---|---:|---:|---:|---:|
|
|
99
|
+
| Native | 51.863 | 53.005 | 33,317 | 34,087 |
|
|
100
|
+
| Portable | 20.498 | 20.926 | 11,370 | 11,613 |
|
|
101
|
+
| JSON | 20.379 | 20.880 | 11,370 | 11,613 |
|
|
102
|
+
|
|
103
|
+
The fresh matrix contains 252 measured rows and thirty-six excluded warmups. The original-baseline matrix is also complete. It preserves its first 245 rows unchanged and adds 43 resumed rows with the original worker and verified library hashes. It has 252 measured rows and thirty-six excluded warmups. The 10,000-record native file case combines one earlier and six resumed original-baseline samples, and two earlier and five resumed optimized samples. These are historical/resumed results, separate from the fresh comparison above.
|
|
104
|
+
|
|
105
|
+
The table below gives original-baseline medians, in seconds, with seven measured samples per case. It shows why the earlier memory-store and construction changes must remain comparison points.
|
|
106
|
+
|
|
107
|
+
| Records | Store | Original insert | Original full read | Original reassign |
|
|
108
|
+
|---:|---|---:|---:|---:|
|
|
109
|
+
| 58 | memory | 0.325 | 0.086 | 0.404 |
|
|
110
|
+
| 58 | file | 0.422 | 0.135 | 0.417 |
|
|
111
|
+
| 1,000 | memory | 34.973 | 1.366 | 68.300 |
|
|
112
|
+
| 1,000 | file | 12.405 | 2.302 | 12.982 |
|
|
113
|
+
| 10,000 | memory | 2,277.276 | 13.995 | 3,069.151 |
|
|
114
|
+
| 10,000 | file | 165.205 | 22.453 | 202.403 |
|
|
115
|
+
|
|
116
|
+
For 10,000 records, the original history occupies 232,935,769 bytes after thirteen commits. Optimized rb01 occupies 104,923,609 bytes; packed rb02 occupies 2,216,527 bytes. An original nested update adds 3,617 bytes, compared with 891 packed bytes. The two rb01 implementations retain the same 26,821,960 bytes after compaction, while packing retains 1,106,827 bytes.
|
|
117
|
+
|
|
118
|
+
The archived [representation experiments](benchmarks/native-records/packing-design.md) contain the selection evidence and its single-sample limitations.
|
|
119
|
+
|
|
120
|
+
## Why the previous representation was expensive
|
|
121
|
+
|
|
122
|
+
An rb01 six-field map needs seven 160-byte array records for its envelope and entries before adding lookup indexes, insertion-order indexes, or scalar payloads. Of those 1,120 structural bytes, 810 are unused leaf slots. The initial encoding also writes intermediate container versions that compaction later removes.
|
|
123
|
+
|
|
124
|
+
The earlier optimized implementation removes many intermediate writes and repeated traversals. Its compacted size is unchanged. That result separates construction waste from retained representation overhead.
|
|
125
|
+
|
|
126
|
+
The archived instrumented 1,000-record memory profile measures 63,023 checkpoint calls in the original implementation, capturing 148,788,474 cursor slots. Checkpoints account for 17.63 of 35.17 measured CPU seconds and 149.27 million of 157.41 million allocations. Optimized rb01 reduces those figures to 23,013 calls, 4,511,207 captured slots, 0.666 CPU seconds, and 4.68 million checkpoint allocations. Inclusive method costs overlap; instrumentation changes timings.
|
|
127
|
+
|
|
128
|
+
A separate retained-tail control exposes the original memory-store amplification. It retains twenty 144-byte tail reads from a 1 MiB store, writing one byte after each read. Original String memory grows by 20,973,940 bytes because shared tail slices force complete-store copies on later writes. Copying only the requested bytes reduces that measured increase to 4,500 bytes. The workload uses the same read/write path, but these profiles do not attribute an exact fraction of its elapsed time to those copies. This is separate from the packed representation's retained-size improvement.
|
|
129
|
+
|
|
130
|
+
Optimized rb01 still calls key encoding 12,003 times in the 1,000-record profile, costing 0.939 instrumented CPU seconds and 972,295 allocations. Field dictionaries and bounded validated key caches target this repeated work directly. The archived [rb01 profiles](benchmarks/native-records/rb01-profiles.json.gz) retain method and append-size details.
|
|
131
|
+
|
|
132
|
+
In rb02, a literal six-field map occupies 116 bytes. A map using a field dictionary occupies 71 bytes, with one shared 62-byte dictionary per repeated shape. Original key slots directly preserve order and encodings. Short scans replace separate lookup and order indexes for up to sixteen members.
|
|
133
|
+
|
|
134
|
+
Ruby fidelity still has a storage cost. A value slot distinguishes types and preserves exact numeric representations. String payloads retain their encoding. Canonical key comparison can treat keys as equal while retaining the first key's original representation. Custom codec payloads retain their identifiers and bytes. These requirements do not require padded entry envelopes or separate indexes for small maps.
|
|
135
|
+
|
|
136
|
+
## Selected design
|
|
137
|
+
|
|
138
|
+
Core records contain an eight-byte header and at most thirty-two nine-byte slots. Their metadata selects the native container representation. Small arrays use up to sixteen slots. Larger arrays use sixteen-slot tree blocks and a compact wrapper. Construction holds at most sixteen slots per active tree level and writes each completed block once.
|
|
139
|
+
|
|
140
|
+
Small maps and sets preserve insertion order in their key slots. Maps with more than sixteen members, canonical keys larger than 128 bytes, or encoded key payloads larger than 256 bytes use the existing indexed representation. Value-only updates can reuse an existing field dictionary. Key changes can write a literal packed map.
|
|
141
|
+
|
|
142
|
+
Each encoding operation can share at most 256 short String or Symbol payloads and 64 field dictionaries. Identity includes scalar class, encoding, and exact bytes. Only values up to 64 source bytes qualify. Materialized mutable Strings remain independent Ruby objects. Dictionary read caches belong to a single read-only materialization operation; transaction reads do not retain them across mutations.
|
|
143
|
+
|
|
144
|
+
Large values remain separate byte records. String, Symbol, and codec payloads append with bounded prefixes and 64 KiB chunks. An update copies the affected record, bounded tree blocks on its ancestor path, and transaction history metadata. It does not decode unrelated array elements or oversized adjacent values.
|
|
145
|
+
|
|
146
|
+
The [wire contract](ruby-profile-v2.md) defines the exact record metadata, limits, rejection rules, and reserved profile identifiers.
|
|
147
|
+
|
|
148
|
+
## Production byte accounting and profiles
|
|
149
|
+
|
|
150
|
+
The production compactor accounts for every byte in the updated 10,000-record file. Memory and file probes produce the same ledger.
|
|
151
|
+
|
|
152
|
+
| Retained component | Bytes |
|
|
153
|
+
|---|---:|
|
|
154
|
+
| 10,000 row records, 71 bytes each | 710,000 |
|
|
155
|
+
| 669 array blocks and one array header | 96,352 |
|
|
156
|
+
| Array wrapper | 17 |
|
|
157
|
+
| Shared six-field dictionary | 62 |
|
|
158
|
+
| String payload records | 299,945 |
|
|
159
|
+
| Root map | 44 |
|
|
160
|
+
| File initialization, history, and trailers | 407 |
|
|
161
|
+
| Total | 1,106,827 |
|
|
162
|
+
|
|
163
|
+
String storage comprises 298,890 bytes for method names, 852 for shared namespaces and paths, and 203 for original keys. The 407-byte remainder contains a 37-byte header, two 160-byte history records, and two 25-byte trailers. One initialization history record and trailer are unreachable, a fixed 185 bytes that remain after compaction. The retained graph itself occupies 1,106,420 bytes.
|
|
164
|
+
|
|
165
|
+
The 891-byte nested-update growth has a direct structural explanation: one 71-byte row, four 144-byte array blocks, a 16-byte array header, a 17-byte wrapper, a 26-byte root map, 160 history bytes, and a 25-byte trailer. This is the affected path, not a replacement of the complete array.
|
|
166
|
+
|
|
167
|
+
Separate instrumented file probes measure the following logical store API traffic for 10,000 records. These are requested bytes and calls, not physical disk I/O. Compaction includes temporary mapping stores.
|
|
168
|
+
|
|
169
|
+
| Native operation | Read bytes | Written bytes | Read calls | Write calls |
|
|
170
|
+
|---|---:|---:|---:|---:|
|
|
171
|
+
| Insert | 1,154 | 1,106,762 | 31 | 50,820 |
|
|
172
|
+
| Full read | 1,731,495 | 0 | 110,745 | 0 |
|
|
173
|
+
| Three indexed reads | 11,363 | 0 | 461 | 0 |
|
|
174
|
+
| Identical reassignment | 1,644 | 1,106,579 | 56 | 50,815 |
|
|
175
|
+
| Nested update | 7,773 | 969 | 296 | 18 |
|
|
176
|
+
| Ten commits | 19,025 | 2,737 | 795 | 74 |
|
|
177
|
+
| Compaction | 24,843,657 | 14,767,778 | 387,207 | 309,905 |
|
|
178
|
+
|
|
179
|
+
Reopened indexed and complete reads have the same byte/call counts as the corresponding original-handle reads. Opening the file itself reads 651 bytes in twenty calls. JSON's three indexed reads request 1,160,289 bytes. Its nested update reads 1,161,760 and writes 1,159,844 bytes. Native's 969 written API bytes exceed its 891-byte file growth because writes also overwrite metadata.
|
|
180
|
+
|
|
181
|
+
Streaming scalar prefixes increase small write-call counts compared with the prototype's joined scalar payloads. This preserves bounded copying for oversized values while leaving scalar wire bytes unchanged. It is a measured trade-off, not an additional storage saving.
|
|
182
|
+
|
|
183
|
+
In the production 1,000-record file CPU profile, insert takes 0.480 instrumented CPU seconds. Input guards account for 0.303 seconds across 7,010 calls, about 63% of that total. Encoding dispatch costs 0.075 seconds across 12,001 calls; record append costs 0.00972 seconds across 1,003 calls. Only three checkpoints remain, capturing eleven cursor slots. Key encoding during a full read falls to three calls.
|
|
184
|
+
|
|
185
|
+
Complete read takes 0.135 instrumented CPU seconds. Scalar decoding accounts for 0.0606 seconds across 6,010 calls, record reads for 0.0304 seconds across 1,007 calls, and database reads for 0.0410 seconds across 11,142 calls. These inclusive costs overlap. The profiler adds allocations and method overhead; use the uninstrumented matrix for latency and allocation comparisons.
|
|
186
|
+
|
|
187
|
+
Compaction's temporary offset map remains a bottleneck after its 16,384-entry cache fills. Its traffic is much larger than the retained graph. The 1,000-record graph fits below that threshold, while the 10,000-record graph exceeds it. This explains the observed compaction scaling step without assuming proportional scaling from the smaller case.
|
|
188
|
+
|
|
189
|
+
## Alternatives and remaining costs
|
|
190
|
+
|
|
191
|
+
Ninety short serial prototype probes compared the previous indexed implementation, packed maps with incremental arrays, completed-block array construction, shared key payloads, field dictionaries, and validation changes. Each probe was a working implementation. The archive retains their sources and exact input.
|
|
192
|
+
|
|
193
|
+
The original packing study considered inline typed cells and larger byte chunks without implementing them. They might remove slot padding and scalar headers. They also require another parser and relocation rules, and can enlarge small update copies. The selected record design has direct measured evidence and preserves useful selective operations. It is not a demonstrated storage lower bound.
|
|
194
|
+
|
|
195
|
+
The follow-up [JSON performance experiments](benchmarks/native-pages/README.md) measure JSON pages, field dictionaries, column layouts, compressed pages, and typed binary pages. Those prototypes approach JSON bulk speed but do not implement the complete Ruby profile. Their update copying exceeds rb02's bounded record path.
|
|
196
|
+
|
|
197
|
+
The [compiled rb02 experiment](benchmarks/native-batch/README.md) measures C batching through public native transactions and views. It preserves ordinary records and bounded updates, while separating interpreter overhead from storage layout costs.
|
|
198
|
+
|
|
199
|
+
Repeated validation was a separate CPU cost. A source-hashed 1,000-record probe reduced input-guard calls from 30,048 to 7,010 during insert, from thirteen to three during a full read, and from fifty-two to fifteen during an update. Exact immediate scalar classes skip per-object singleton inspection. Profile-owned validated encoding removes duplicate checks. Stored built-in keys do not repeat application-object introspection.
|
|
200
|
+
|
|
201
|
+
Unchanged reassignment still validates and encodes a complete new graph. There is no persistent whole-graph deduplication. A single-use dictionary can cost more than a literal map; the bounded dictionary table limits this extra cost. Large maps still have the earlier indexed representation's overhead. Full native reads still perform many small record and scalar decodes. Compaction uses a bounded offset cache and can spill mapping data to temporary storage.
|
|
202
|
+
|
|
203
|
+
The JSON control is faster for complete encoding and decoding on this workload. Its indexed reads and small updates decode the complete JSON payload, and its updates rewrite it. Native packing preserves typed values and selective operations. JSON-level native performance has not been established. Fixed nine-byte slots and repeated scalar encoding headers remain representation choices, not proven lower bounds; inline cells could reduce them further, but that benefit has not been measured.
|
|
204
|
+
|
|
205
|
+
## Correctness and verification
|
|
206
|
+
|
|
207
|
+
The implementation gate passed 489 tests and 41,640 assertions, with no failures, errors, or skips. Style, RBS validation, Steep, 100% typed calls across seventy library files, CRAP checks, packaged examples, and gem inspection passed through `bundle exec ruby script/ci.rb`. Focused native tests also passed on Ruby 3.3.11 and 3.4.9, each with 136 tests and 2,532 assertions.
|
|
208
|
+
|
|
209
|
+
Regression tests cover exact Float bits, numeric and String fidelity, canonical keys, insertion order, malformed records, threshold transitions, bounded builder behavior, snapshots, rollback, writer coordination, and failure injection. Independent review and QA include concurrent and reentrant materialization, malformed dictionary references, stored cycles, and mixed public mutations. The [review record](benchmarks/native-records/packing-review.md) states the review scope and same-family validation limit.
|
|
210
|
+
|
|
211
|
+
`bundle exec rake stress` passed five tests and 326 assertions. It retains the existing Linux memory suite and adds native workloads in Docker with 256 MiB memory and no swap. A 128 MiB String remains correct through append, snapshot retention, replacement, compaction, and reopen. A 12,500-record workload with 64 KiB values grows by 873 bytes for a small nested update and compacts to 820,684,940 bytes. Both native cases report zero OOM and OOM-kill events. Cgroup peaks reach the configured limit under reclaim pressure; this is not evidence of lower peak resident application memory.
|
|
212
|
+
|
|
213
|
+
`bundle exec rake interop` passed all four pinned Go, TypeScript, Java, and Zig reference checks. Portable storage, bidirectional all-kind values, history, compaction, interrupted replication, alternate hashing, and opaque Ruby scalar maintenance inside portable graphs remain covered. Existing pinned-reference numeric limits remain documented by that suite.
|
|
214
|
+
|
|
215
|
+
Native rb02 graphs use Core Record tag 17. Pinned reference implementations do not understand that extension and cannot maintain those graphs. Opaque Ruby scalar payloads remain unchanged and can still be maintained inside supported portable graphs. This is an intentional reduction of native container interoperability, not a claimed cross-language rb02 guarantee.
|
|
216
|
+
|
|
217
|
+
## Reproduction
|
|
218
|
+
|
|
219
|
+
The [final provenance](benchmarks/native-records/packing-final-provenance.json) records source/input hashes and SHA-256 digests for every compressed artifact.
|
|
220
|
+
|
|
221
|
+
| Evidence | Artifacts |
|
|
222
|
+
|---|---|
|
|
223
|
+
| Raw matrices | [Fresh paired samples](benchmarks/native-records/packing-final-samples.json.gz), [historical and resumed samples](benchmarks/native-records/rb01-complete-samples.json.gz) |
|
|
224
|
+
| Statistics | [Validated medians, ranges, allocations, and growth](benchmarks/native-records/packing-final-summary.json.gz) |
|
|
225
|
+
| Production diagnosis | [Traffic](benchmarks/native-records/packing-production-traffic.json.gz), [retained-byte ledgers](benchmarks/native-records/packing-production-bytes.json.gz), [CPU profiles](benchmarks/native-records/packing-production-profiles.json.gz) |
|
|
226
|
+
| Reproduction and checks | [Sources and exact input](benchmarks/native-records/packing-production-sources.json.gz), [verification evidence](benchmarks/native-records/packing-verification.json.gz) |
|
|
227
|
+
|
|
228
|
+
Run the comparison from this checkout. Its library files match the frozen packed revision; the report records the current commit. Checking out `af53aeb` separately reproduces the recorded candidate commit with the same timing driver.
|
|
229
|
+
|
|
230
|
+
After a squash merge, fetch the comparison commits from [PR #4](https://github.com/svyatov/xitdb-ruby/pull/4) before running the benchmark:
|
|
231
|
+
|
|
232
|
+
```sh
|
|
233
|
+
git fetch origin refs/pull/4/head
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
This fetch restores the optimized rb01 and frozen packed commits without changing the checkout.
|
|
237
|
+
|
|
238
|
+
```sh
|
|
239
|
+
bundle exec ruby script/native_benchmark.rb --baseline fde9a5dda601643398289f5bd0ebfdbfa7f2089e --output pkg/native-packed-final.json
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Use `--resume` with the same candidate commit, options, Ruby, fixture, and driver to continue an interrupted run. The driver checks that provenance, then skips completed rows. For a short check, add `--counts fixture --stores file --samples 1 --warmups 0` and choose a different output path.
|
|
243
|
+
|
|
244
|
+
Run separate byte-traffic and retained-byte probes from this checkout. These extra instrumentation drivers were added after the timing freeze.
|
|
245
|
+
|
|
246
|
+
```sh
|
|
247
|
+
bundle exec ruby script/native_traffic.rb --count 10000 --store file --layout ruby --output pkg/native-traffic.json
|
|
248
|
+
bundle exec ruby script/native_byte_account.rb --count 10000 --store file --output pkg/native-byte-account.json
|
|
249
|
+
bundle exec ruby script/native_profile.rb --count 1000 --store file --output pkg/native-profile.json
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
`XITDB_LIBROOT` can select an extracted comparison revision. Traffic counts are logical store API requests, including repeated reads and temporary compaction stores, not operating-system disk traffic. The byte ledger counts first-time graph reservations during compaction and reports remaining file/history overhead separately.
|
|
253
|
+
|
|
254
|
+
Prototype replay commands, archived sources, and historical provenance are linked from the [experiment report](benchmarks/native-records/packing-design.md).
|
data/docs/ruby-profile-v1.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Ruby profile version 1 wire contract
|
|
2
2
|
|
|
3
|
+
This is the historical `rb01` contract. Native handles use the incompatible [version 2 contract](ruby-profile-v2.md).
|
|
4
|
+
|
|
3
5
|
This contract defines the `rb01` profile without changing upstream format version 1.
|
|
4
6
|
|
|
5
7
|
## File identity
|