Repository navigation
Releases
Cellar v1.2.0
What is new, in short:
- The whole cache in one memory. The keeper keeps everything in one
WebAssembly.Memory: its index, every body, its own budget. You can hand it a memory of your own (a virtual machine's RAM, say) withopenKeeper({ memory }), and it makes no other buffer at all. A thread gets that memory once and reads every body in it, including bodies placed later. - The keeper as a page file.
keeper.evict(name, view, flags)writes a page to the disk straight from where it lies, even in memory the keeper does not manage, andkeeper.restore(name, view)reads it back into place.dropforgets a page and its copy on the disk;evictAllwrites many pages in one go (straight from memory when they lie side by side) and tells you how many went out, so you only retry the rest. A page that did not go out leaves the name exactly as it was. The remote keeper can do both, naming a page by where it lies in memory both sides share. - Bodies on a frame boundary.
segmentAlignmakes every segment start on a boundary you choose (4 KiB by default), so a large body can be mapped straight into a program's pages without a copy. - Frames go to the browser at any size. All memory now has a fixed length, so
VideoFrame.copyTo,GPUQueue.writeTextureand OPFS take any body. There is no flag for it any more.
Fixed from 1.1:
- A large body being written to disk in parts is written once: a
savemeanwhile finishes the same write, adropstops it, andcloseends it, where before it could be written twice and its pack never freed. - The keeper forgets which worker reserved what once the reservation is committed or let go, instead of keeping it until the worker ends.
- A record replaced while its last reader left, or its writer committed or gave up, is let go of at once instead of holding its room until a later sweep.
- A body of its own segment written again smaller fits a full budget: the pages it no longer needs are given back.
- A channel refuses a request too large for its slots at once, instead of first waiting for a slot.
If you used 1.1: all threads of one program must use the same version again, because the shared layout changed (saved data on disk still opens). Changed from 1.1:
- A thread is handed
keeper.shared, now{ memory, root }, and nothing else:createReader({ shared, keeper }). - Removed, as there is nothing left for them to do:
keeper.segmentBuffers(), theannounceoption,reader.adopt(), theknownargument ofreserveandraise, therefusedUnseenandspareAddressBytesfigures, andreserveFlags({ fixed }).reserveFlagsnow refuses any option it does not know, so old code that still passesfixedfails loudly instead of quietly. keeper.reserveandKeeperCalls.reserveare(name, length, flags, place, writer?);raiseis(name). The offset inplaceis where the body lies in the memory, read as an unsigned number (place[P_OFFSET] >>> 0).- New:
createArena({ bytes, most })makes a memory for the keeper;createAccountMemorytakesmemoryto place its words in one, and its answer says where they start (at);figures().segmentFailurescounts ranges the memory refused.
Cellar v1.1.1
Two fixes found while building a video editor on Cellar:
- Cellar loads in an AudioWorklet. Importing the library made a text decoder at once, and an AudioWorklet has none, so a worklet that imported Cellar never registered. Nothing is taken from the host until it is used; a worklet reads a ring from its
process()withdrainorpeek, never a wait. - Large frames handed to the browser.
VideoFrame.copyTo,GPUQueue.writeTextureand OPFS refuse memory that can grow, and a body larger than a quarter ofsegmentByteswas placed in memory that can. A body reserved withreserveFlags({ fixed: true })now always lies in fixed memory, up to a whole segment; one larger is refused at once. A 4K frame needs segments of 32 MiB, not 128 MiB.
Cellar v1.1.0
What is new, in short:
- One memory budget for everything. Cellar can now count every byte a program holds - its cache, a WebAssembly memory, compiled code - in one place, and free old cached data first when something new does not fit.
- Two-way calls. A link lets two threads call each other; a thread waiting for its answer still answers the other side meanwhile, so the two never lock each other up.
- Tables. Counters and small records that one thread writes and any thread reads at any time, without asking the writer. Also a list of handles any thread can take and give back.
- The cache from any thread. The thread that owns the cache can be asked from another thread, over a channel or a link.
- Less waiting, less waking. Each side of a link sleeps on one word, and a full ring wakes its writer only when the writer is actually waiting for room. A call that could not be sent in its time limit is not sent late.
- Nothing left stuck. Space nobody needs any more - a write a thread abandoned, an old record its last reader has left - is reclaimed the next time the cache needs room.
If you used 1.0.0: a few calls changed (listed below), and all threads of one program must use the same version, because the shared memory layout changed. Data already saved to disk still opens.
Changed from 1.0.0:
INDEX_FILES,packFileandreadSavedmoved to the new entry@bottlify/cellar/advanced, together with the other low-level helpers.- Write options are now one number made by
reserveFlags({ onlyCopy, disk, idle }): pass it toreader.reserve(name, length, flags)andreader.put(name, bytes, flags)instead of an options object. keeper.reserve(andKeeperCalls.reserve) is(name, length, flags, known, place, writer?): it fills theplacearray you pass and returns true, or returns false, instead of creating an object.createRingMemory(capacity, bell, roomBell)takes a second doorbell, rung when room frees up while the writer waits for it.- Too many queued calls: both a link side and a channel client limit them with
unsentLimit, and refuse the extra call as not sent. - A time limit now also covers waiting to send: a call that could not get room in time fails with
ChannelNotSentorLinkNotSent; a limit of 0 sends only if there is room right now. - A link side closes in one way only, whoever starts it, and only one
servemay run on a side. account.fits(bytes, kind?, given?)can count memory about to be given back.- The shared memory layouts of the cache, rings and tables changed; memory from another version is refused when opened.
Added:
- Memory budget:
createAccountMemory,openAccount,openCharge,memoryBytes,ACCOUNT_UNIT,RUN_HOLDER. - Links:
createLinkMemory,openLink,LinkClosed,LinkNotSent,LinkNotAnswered. - Tables:
createTableMemory,openTable. - The cache from another thread:
openKeeperClient,serveKeeperChannel,answerKeeper,keeperWords,linkCarrier. - Clearer channel errors:
ChannelNotSent(the call never left) andChannelNotAnswered(it left, no answer in time). - Helpers:
reserveFlags,mayWait(may this thread block?),grainsOf. - Documentation for each part, including how long data lives, who may write where, and what time limits cover; and a page on how all this is tested.
Cellar v1.0.0
The first version on npm. Cellar lets JavaScript threads share memory directly: call each other, pass streams of data and wait for each other, without sending messages through postMessage. A small call between two threads takes about 2 µs instead of about 38 µs (Benchmarks); made for the browser, also runs on Node.js 22 and later, no dependencies.
What it contains, one entry, @bottlify/cellar: the cache (openKeeper, createReader, INDEX_FILES, packFile, readSaved), channels (createChannel, openClient, openServer, ChannelClosed, ChannelFailed), doorbells (createDoorbell, openDoorbell, publish, ring, wake, waitFor, waitForAsync, createSpin, deadlineOf, SPIN_MS), rings (createRingMemory, openRing, RingClosed) and journals (createJournalMemory, openJournal).