WEBVTT

00:00:00.500 --> 00:00:03.091
Follow Inventory's item map into main memory.

00:00:03.991 --> 00:00:06.713
Nyxus allocates its native B-tree nodes there.

00:00:07.611 --> 00:00:10.892
An allocator test makes the same choice with a simpler collection,

00:00:11.022 --> 00:00:11.569
a vector.

00:00:12.468 --> 00:00:14.681
The native test starts with two vectors.

00:00:15.580 --> 00:00:18.470
An ordinary Rust vector gets its buffer from Global.

00:00:19.369 --> 00:00:21.530
The second constructor names Nyxus.

00:00:22.429 --> 00:00:25.502
The retained buffer starts with one, two, three.

00:00:26.400 --> 00:00:30.515
In a canister, the runtime and Nyxus ask one provider for sixty-four

00:00:30.528 --> 00:00:31.713
kibibyte pages.

00:00:32.611 --> 00:00:35.124
It tracks which allocator owns each claim.

00:00:36.022 --> 00:00:39.434
As either client needs space, it can claim available pages from

00:00:39.447 --> 00:00:40.410
that same pool.

00:00:42.533 --> 00:00:46.465
Inside a page, the allocator divides space into spans.

00:00:47.365 --> 00:00:51.298
A span serves one size class, with slots of equal size.

00:00:52.196 --> 00:00:55.347
A nine-byte request aligned to eight bytes takes a sixteen-byte

00:00:55.360 --> 00:00:55.868
slot.

00:00:56.766 --> 00:01:00.204
Both layouts fit the same slot, so growing to sixteen keeps

00:01:00.217 --> 00:01:01.180
the same address.

00:01:02.079 --> 00:01:04.162
The test requests zeroed growth.

00:01:05.061 --> 00:01:08.238
The first nine bytes keep their values and the seven added bytes

00:01:08.251 --> 00:01:09.240
start at zero.

00:01:10.139 --> 00:01:12.886
Give the vector more elements and it eventually needs a larger

00:01:12.899 --> 00:01:13.329
buffer.

00:01:14.227 --> 00:01:17.079
The native test reaches twenty thousand integers.

00:01:17.977 --> 00:01:21.415
For a large allocation in Wasm, the allocator claims a run of

00:01:21.428 --> 00:01:22.287
whole pages.

00:01:23.186 --> 00:01:26.493
When resizing moves a buffer, the existing elements follow it

00:01:26.506 --> 00:01:27.704
into the new space.

00:01:29.833 --> 00:01:31.838
Dropping the vector releases its buffer.

00:01:32.738 --> 00:01:35.394
A whole-page run goes straight back to the provider.

00:01:36.293 --> 00:01:38.559
Other live allocations stay where they are.

00:01:39.457 --> 00:01:42.803
On the smaller page, a freed slot can take another request of

00:01:42.816 --> 00:01:43.598
its class.

00:01:44.496 --> 00:01:48.363
When the last allocation goes, the whole page becomes available.

00:01:49.262 --> 00:01:51.306
Either allocator can claim it next.

00:01:52.204 --> 00:01:54.483
The Wasm memory extent stays the same.

00:01:55.381 --> 00:01:59.783
In the next canister, Payloads uses Nyxus and Records uses Hylix.

00:02:00.681 --> 00:02:02.335
Both attach to the same root.

00:02:03.233 --> 00:02:05.954
Records keeps a small descriptor in main memory.

00:02:06.853 --> 00:02:08.715
Its data lives in stable memory.

