Skip to content
API REFERENCEUsage guides →

Plans and costs: opt ​

cellpack::opt represents cache residency, compiler options, machine costs, modeled loads and serial reference policies. The application's bound Loader supplies the graph and high-level compilation entry points. The runtime executes the resulting plan. Online compilation makes decisions ahead of the workers, rather than on each worker cache lookup. For a complete program and mode selection, use the cache planning guide.

Look up the contract you need

Compilation and replay ​

Loader methodInputReturn / effect
plan_optionsCache bytesOptions with loader-derived gap and default costs
compileStored &[CellId], optionsOwned offline Plan
replayPlan and exact stored sequencePlanSummary without record loading
replay_with_costSame plus another cost modelRepriced summary, unchanged decisions
compile_onlineStored sequence, finite-horizon optionsCollected plan and OnlineStats
plan_onlineGeneral Accesses, optionsOnline compiler statistics without loading
onlineValidated optionsPlanning::Online for a run

Offline plans require a stored sequence. Its length must be divisible by the schema count; each value is a global CellId. Online planning accepts computed Accesses with the same ordering and determinism requirements. A collected online Plan still binds to the exact stored sequence supplied to compile_online. Compiler thread count affects sharding and can affect decisions; scheduling order of the same compilation does not define the policy.

PlanOptions ​

PlanOptions::new(cache_bytes, gap) uses 16 compiler threads, the Time objective, no cost model, no rows or block merging, Incremental row policy, and no explicit horizon or chunk. Loader::plan_options additionally derives the gap from the loader and supplies an NVMe default model with one output-cost entry per schema. It is the usual starting point for a loader.

Units and validation ​

FieldUnit and accepted values
cache_bytesBytes; usable frames are cache_bytes / page_size, at most u32::MAX
gapPositive slots; gap × slot_cells × schemas must be below u32::MAX accesses
horizonOptional slots; when explicit, at least gap
chunkOptional positive accesses; None uses DEFAULT_CHUNK = 16384
threadsCompiler count; the engine treats zero as one
cpusOptional logical CPU IDs; empty inherits affinity, invalid or clamped CPU sets fail
block_pagesNone or 2–128 pages; requires a cost model

The execution window is in slots and cannot exceed the reuse gap. Unlike the options, Plan::distance() and OnlineStats::{distance, horizon, chunk} use accesses. A slot contains slot_cells × schemas accesses.

Offline compilation uses the whole sequence as its horizon. Online compilation starts from the configured horizon, or twice the source cell count times the schema count in accesses. It raises that value to at least distance + chunk and clips it to the sequence length (max(1) for an empty sequence). The returned OnlineStats reports this effective horizon.

Objectives and retained objects ​

ChoiceContract
PlanObjective::MissesPage-only miss objective; decoded-row caching is off
PlanObjective::TimeMinimize modeled time under declared costs
rows = trueRequires a cost model; row selection takes effect under Time with nonzero frame capacity
RowPolicy::IncrementalOnline/offline reuse-interval decisions
RowPolicy::GlobalWhole-sequence row reference; active row selection requires a stored slice and full-sequence horizon
block_pagesOptional merged admission size; requires costs
cache_bytesPlanned frame budget, not total RSS

Under Misses, setting rows = true does not enable row caching. Without a cost model, setting rows or block merging is an error. Enabling row candidates does not guarantee row admission: they compete with pages for the same frame budget.

Rows retain stored dtype and standard ids. Their size includes decompressed payload and page rounding; a row can occupy noncontiguous frames. Row hits still gather, map and process the row. Process outputs are not cached.

Plan and Residency ​

Plan contains immutable residency and frame assignments plus compatibility identities. Residency describes an Object::Page or Object::Row, its admission and last use, and assigned frame extent. frames_of resolves its frame list.

Plan queryMeaning
len / schemas / slot_cellsAccess count / schema count / positions per slot
reuse_gap / distanceReservation gap in slots / accesses
cache_bytes / cache_framesDeclared byte budget / usable whole-page frames
cost / summaryOptional model and compiled summary
residencies / frames_ofImmutable planned contents
write / openBinary file persistence
to_bytes / from_bytesOwned byte representation

CPKPLAN1 plans bind to inputs, mappings, schemas, process identities, slot size and exact access contents. prepare and replay check compatibility against the actual loader and sequence. open and from_bytes read the plan representation; successful deserialization alone does not establish graph compatibility. A serialized plan is not a portable promise of identical throughput on different hardware. Keep process identities synchronized with callback/configuration changes.

CostModel and resource accounting ​

ComponentDescribes
CapacityPhysical worker cores, device IOPS/bandwidth, memory bandwidth, overlap share
InputCostPer-record, per-element and cold-chunk decode work
RowCostPer-payload-byte gather and row-admission work
OutputCostMapping, filling, processing and partial-row costs per schema
ProcessCostProcess-size bands ending at declared maximum elements
convertPer-element cost per loader Conversion class
LoadsRequests, device bytes, core-seconds and memory traffic
PricesMarginal values used to compare reuse candidates

Operation costs use core-seconds; capacity converts them into modeled wall time. Output-cost order must match schema order. seconds, service and prices operate on a load vector; their outputs are model results, not measurements.

For loads R requests, B device bytes, C core-seconds and M memory bytes:

text
device = max(R / iops, B / bandwidth)
workers = C / cores
seconds = max(max(device, workers) + serial * min(device, workers),
              M / memory_bandwidth)

service returns the four independent service times in request, device-byte, core and memory order. prices assigns marginal seconds per load unit near the supplied workload; Prices::value(loads) values a change at those prices.

Compilation validates positive finite capacities, finite nonnegative operation costs, serial in [0, 1], a positive bucket, and exactly one output entry per schema. Nonempty process-cost curves have increasing inclusive max_elements bounds ending at u32::MAX. Loading a standalone cost-model byte representation checks its encoding; graph-specific validation happens at compilation/replay.

CostModel::defaults provides hardware-tier defaults; opt::defaults::model and Tier select those defaults explicitly. Calibration records are managed by the application. Binary to_bytes/from_bytes is available without Serde; optional serde adds structured serialization derives.

Read summaries without mixing evidence ​

ResultMeaning
PlanSummary countersSerial action counts, including requests, reads, decode work and hits
peak_bytesMaximum bytes retained in serial access order
concurrent_peak_bytesPeak with each residency reserved from start − distance
PlanSummary::seconds()Sum of modeled time over four sequence quarters; zero without costs
OnlineStats::modeled_secondsModeled work of the published accesses; zero without costs
OnlineStats::compile_seconds / waiting_secondsMeasured compilation wall time excluding / measuring wait for plan-ring space

Use statistics and profiling for measured run counters and timing. Repricing a saved plan does not recalibrate it or change its decisions.

Serial page reference ​

PageTrace::from_source extracts page uses for a stored sequence; from_pages constructs a synthetic trace. page_uses and distinct_pages describe it; optimum(capacity_pages) returns a page-only CacheSummary.

This optimal reference has serial page semantics and bypass. It does not include decoded rows, concurrency reservation gaps, sharding, or finite lookahead. Do not describe every production page-and-row plan as globally optimal.

Complete interface index ​

Re-exports ​

InterfaceResponsibility
TierA class of storage, for its default device rates.

Structs ​

InterfaceResponsibility
CacheSummaryWhat a serial run of a trace did: its page uses, and the hits and misses a capacity produced.
CostModelThe loader’s resources on one machine and the work it does per access, record, element, request and cached-row byte. Work is in core-seconds: seconds of one physical core (two workers sharing a core through SMT take it together).
InputCostDecoding records: core-seconds per record, per stored element and per record whose chunk is cold.
LoadsWhat a window of accesses takes from each resource.
OnlineStatsWhat an online compilation did.
OutputCostWhat one output schema’s delivery costs, per element, per row and per call.
PageTraceCanonical page requests: cells in access order, each cell’s pages in file order. This serial reference has no execution window, reuse-gap reservation or management cost.
PlanA cache plan: the residencies a compilation chose, the frames they hold, and what they were compiled for.
PlanOptionsWhat a compilation optimizes for: the budget, the reuse gap, the objective and the cost model of one loader on one machine.
PlanSummaryThe serial execution of a plan, as an independent replay counts it.
PricesMarginal seconds of a window’s modeled time per unit of each load: the gradient of a smoothed T at the loads it was taken at. Saving loads x is worth prices.value(x) seconds.
ProcessCostOne band of a process function’s size curve: the costs that hold for a row of up to max_elements elements.
ResidencyOne residency: an object held from its admission through its last use.
RowCostCached rows: core-seconds of gathering one into a worker’s scratch and of building and writing one, both per payload byte.

Enums ​

InterfaceResponsibility
ObjectA cached object.
PlanObjectiveWhat a compilation minimizes.
RowPolicyRow selection of page+row compilations.

Constants ​

InterfaceResponsibility
DEFAULT_CHUNKDefault compilation chunk in accesses.
DEFAULT_COMPILE_THREADSDefault compiler threads: a fixed count, not derived from the machine.

Functions ​

InterfaceResponsibility
access_fingerprintIdentity of an access sequence, checked before a plan is used.
default_distanceDefault execution window in accesses for a worker count and in-flight depth: four times the accesses in flight.

Default-model API ​

Structs ​

InterfaceResponsibility
HostThe host’s worker costs and memory bandwidth.
StorageDevice rates of a tier and its per-request worker cost.

Enums ​

InterfaceResponsibility
TierA class of storage, for its default device rates.

Constants ​

InterfaceResponsibility
BUCKETAccesses per priced window.
HOSTWorker costs of the reference machine, in core-seconds.

Functions ​

InterfaceResponsibility
builtinThe built-in dense output.
processA process function nothing was measured for.
storageThe stored rates of a tier: sustained random reads, and the loader’s per-request cost measured on the reference machine.
Definition