Documentation
¶
Overview ¶
Package benchmarks measures the memory, collector and access costs of cnfgo representations against ordinary Go objects on a reproducible synthetic data set. The cmd/report program runs every scenario in a fresh process and prints the results as Markdown tables.
Index ¶
- Constants
- Variables
- func ColdStart(format, dir string, probe uint64) (time.Duration, int64, error)
- func WriteCatalogSnapshotAtomic(path string, s *CatalogSnapshot) error
- func WriteColdStartFiles(n int, dir string) error
- func WriteItemSnapshotAtomic(path string, s *CatalogSnapshot) error
- type Catalog
- type CatalogSnapshot
- func FreezeCatalog(src *Catalog, opts ...cnfrt.FreezeOption) (*CatalogSnapshot, error)
- func FreezeCyclicCatalog(src *Catalog, opts ...cnfrt.FreezeOption) (*CatalogSnapshot, error)
- func FreezeCyclicItem(src *Item, opts ...cnfrt.FreezeOption) (*CatalogSnapshot, error)
- func FreezeItem(src *Item, opts ...cnfrt.FreezeOption) (*CatalogSnapshot, error)
- func FreezeTreeCatalog(src *Catalog, opts ...cnfrt.FreezeOption) (*CatalogSnapshot, error)
- func FreezeTreeItem(src *Item, opts ...cnfrt.FreezeOption) (*CatalogSnapshot, error)
- func MapCatalogFile(path string, mode cnfrt.VerifyMode) (*CatalogSnapshot, error)
- func MapItemFile(path string, mode cnfrt.VerifyMode) (*CatalogSnapshot, error)
- func UnmarshalCatalogSnapshot(data []byte, mode cnfrt.VerifyMode) (*CatalogSnapshot, error)
- func (s *CatalogSnapshot) Close() error
- func (s *CatalogSnapshot) Cyclic() bool
- func (s *CatalogSnapshot) IsMmap() bool
- func (s *CatalogSnapshot) LenCatalog() int
- func (s *CatalogSnapshot) LenItem() int
- func (s *CatalogSnapshot) LenSeller() int
- func (s *CatalogSnapshot) MarkRetired()
- func (s *CatalogSnapshot) MarshalCNF() ([]byte, error)
- func (s *CatalogSnapshot) Root() CatalogView
- func (s *CatalogSnapshot) RootCatalog() CatalogView
- func (s *CatalogSnapshot) RootItem() ItemView
- func (s *CatalogSnapshot) SizeBytes() int
- func (s *CatalogSnapshot) UnfreezeCatalog() (*Catalog, error)
- func (s *CatalogSnapshot) UnfreezeItem() (*Item, error)
- func (s *CatalogSnapshot) UsesDict() bool
- func (s *CatalogSnapshot) WithRootCatalogFaultSafe(fn func(CatalogView) error) error
- func (s *CatalogSnapshot) WithRootFaultSafe(fn func(CatalogView) error) error
- func (s *CatalogSnapshot) WithRootItemFaultSafe(fn func(ItemView) error) error
- func (s *CatalogSnapshot) WriteTo(w io.Writer) (int64, error)
- type CatalogView
- func (v CatalogView) AppendVersion(dst []byte) []byte
- func (v CatalogView) IsValid() bool
- func (v CatalogView) Items() Uint64ItemHashMapView
- func (v CatalogView) NodeID() cnfrt.NodeID
- func (v CatalogView) Snapshot() *CatalogSnapshot
- func (v CatalogView) Unfreeze() (*Catalog, error)
- func (v CatalogView) Version() string
- func (v CatalogView) VersionEquals(s string) bool
- func (v CatalogView) VersionLen() int
- func (v CatalogView) WithVersion(fn func(string))
- type CompactItem
- func BorrowCompactItem(raw string) (CompactItem, error)
- func BorrowCompactItemBytes(raw []byte) (CompactItem, error)
- func PackCyclicItem(src *Item, opts ...cnfrt.FreezeOption) (CompactItem, error)
- func PackItem(src *Item, opts ...cnfrt.FreezeOption) (CompactItem, error)
- func PackTreeItem(src *Item, opts ...cnfrt.FreezeOption) (CompactItem, error)
- func ParseCompactItem(raw string, mode cnfrt.VerifyMode, opts ...cnfrt.ParseOption) (CompactItem, error)
- func (c CompactItem) Active() bool
- func (c CompactItem) AppendCNF(dst []byte) []byte
- func (CompactItem) CodecCNF() cnfrt.Codec[CompactItem]
- func (c *CompactItem) DecodeCNF(src string) error
- func (c CompactItem) Detach(opts ...cnfrt.FreezeOption) (CompactItem, error)
- func (c CompactItem) Equal(o CompactItem) bool
- func (c CompactItem) ID() uint64
- func (c CompactItem) IsZero() bool
- func (c CompactItem) Price() int64
- func (c CompactItem) Raw() string
- func (c CompactItem) SKU() string
- func (c CompactItem) SKUEquals(v string) bool
- func (c CompactItem) SKULen() int
- func (CompactItem) SchemaHashCNF() uint64
- func (c CompactItem) SizeCNF() int
- func (c CompactItem) Snapshot(mode cnfrt.VerifyMode, opts ...cnfrt.ParseOption) (*CatalogSnapshot, error)
- func (c CompactItem) Stock() int32
- func (c CompactItem) Title() string
- func (c CompactItem) TitleEquals(v string) bool
- func (c CompactItem) TitleLen() int
- func (c CompactItem) TryView() (ItemView, error)
- func (c CompactItem) Unpack() (*Item, error)
- func (c CompactItem) Updated() time.Time
- func (c CompactItem) UsesDict() bool
- func (c CompactItem) View() ItemView
- type CompactStore
- type Dims
- type DimsView
- type FreezeCost
- type Item
- type ItemView
- func (v ItemView) Active() bool
- func (v ItemView) AppendSKU(dst []byte) []byte
- func (v ItemView) AppendTitle(dst []byte) []byte
- func (v ItemView) Attrs() StringStringMapView
- func (v ItemView) Dims() DimsView
- func (v ItemView) ID() uint64
- func (v ItemView) IsValid() bool
- func (v ItemView) NodeID() cnfrt.NodeID
- func (v ItemView) Price() int64
- func (v ItemView) SKU() string
- func (v ItemView) SKUEquals(s string) bool
- func (v ItemView) SKULen() int
- func (v ItemView) Seller() SellerView
- func (v ItemView) Snapshot() *CatalogSnapshot
- func (v ItemView) Stock() int32
- func (v ItemView) Tags() StringSliceView
- func (v ItemView) Title() string
- func (v ItemView) TitleEquals(s string) bool
- func (v ItemView) TitleLen() int
- func (v ItemView) Unfreeze() (*Item, error)
- func (v ItemView) Updated() time.Time
- func (v ItemView) WithSKU(fn func(string))
- func (v ItemView) WithTitle(fn func(string))
- type NativeStore
- type Result
- type Seller
- type SellerView
- func (v SellerView) AppendCountry(dst []byte) []byte
- func (v SellerView) AppendName(dst []byte) []byte
- func (v SellerView) Country() string
- func (v SellerView) CountryEquals(s string) bool
- func (v SellerView) CountryLen() int
- func (v SellerView) ID() uint32
- func (v SellerView) IsValid() bool
- func (v SellerView) Name() string
- func (v SellerView) NameEquals(s string) bool
- func (v SellerView) NameLen() int
- func (v SellerView) NodeID() cnfrt.NodeID
- func (v SellerView) Snapshot() *CatalogSnapshot
- func (v SellerView) Unfreeze() (*Seller, error)
- func (v SellerView) WithCountry(fn func(string))
- func (v SellerView) WithName(fn func(string))
- type SlabBorrowStore
- type SlabStore
- type SnapshotStore
- type Store
- type StringSliceView
- type StringStringMapView
- type Uint64ItemHashMapView
Constants ¶
const ChurnBytes = 2 << 30
ChurnBytes is the default volume of garbage allocated by the churn workload.
const NumSellers = 1000
NumSellers is the number of distinct sellers in a generated catalog.
const SchemaHashCatalog uint64 = 0x474aabe8286f5679
SchemaHashCatalog identifies the layout of CatalogSnapshot images.
Variables ¶
var ColdStarts = []string{"json", "gob", "cnf-trusted", "cnf-checksum", "cnf-untrusted"}
ColdStarts lists the formats accepted by ColdStart.
var HighCardScenarios = []string{
"native",
"compact-map",
"compact-map-dict",
"slabmap-borrow",
"snapshot",
}
HighCardScenarios lists the representative scenarios measured under the high-cardinality (100% unique Title and SKU) workload.
var Scenarios = []string{
"native",
"native-unique",
"native-gogc400",
"native-memlimit",
"compact-map",
"compact-map-dict",
"slabmap",
"slabmap-borrow",
"slabmap-dict",
"slabmap-dict-borrow",
"snapshot",
"snapshot-mmap",
}
Scenarios lists the names accepted by Run.
Functions ¶
func ColdStart ¶
ColdStart loads the catalog in the given format from dir and reads item probe, returning the elapsed time and the size of the file.
func WriteCatalogSnapshotAtomic ¶
func WriteCatalogSnapshotAtomic(path string, s *CatalogSnapshot) error
WriteCatalogSnapshotAtomic writes s to path atomically (temporary file, fsync, rename, directory fsync), so concurrent MapCatalogFile calls never observe a partial file.
func WriteColdStartFiles ¶
WriteColdStartFiles encodes a catalog of n items in every format into dir.
func WriteItemSnapshotAtomic ¶
func WriteItemSnapshotAtomic(path string, s *CatalogSnapshot) error
WriteItemSnapshotAtomic writes s to path atomically; see WriteCatalogSnapshotAtomic.
Types ¶
type Catalog ¶
Catalog is a product catalog indexed by item ID.
func MakeCatalog ¶
MakeCatalog returns a deterministic catalog of n items with IDs 1..n.
func MakeHighCardCatalog ¶
MakeHighCardCatalog returns a deterministic catalog of n items in which every item has both a unique SKU and a unique Title (zero title sharing).
func MakeInternedCatalog ¶
MakeInternedCatalog returns MakeCatalog(n) with every repeated string canonicalized via the standard library's unique.Make[string].
type CatalogSnapshot ¶
type CatalogSnapshot struct {
// contains filtered or unexported fields
}
CatalogSnapshot is an immutable, pointer-free snapshot of an object graph. Every node table and pool is a slice of a flat type without Go pointers, so the garbage collector never scans its contents.
A snapshot is safe for concurrent use. Snapshots opened from memory-mapped files must not be used after Close; string getters on such snapshots return copies.
func FreezeCatalog ¶
func FreezeCatalog(src *Catalog, opts ...cnfrt.FreezeOption) (*CatalogSnapshot, error)
FreezeCatalog freezes the object graph rooted at src into a snapshot. Shared pointers are deduplicated and directed cycles are rejected with cnfrt.ErrCycleDetected.
func FreezeCyclicCatalog ¶
func FreezeCyclicCatalog(src *Catalog, opts ...cnfrt.FreezeOption) (*CatalogSnapshot, error)
FreezeCyclicCatalog freezes src permitting directed cycles; shared pointers are deduplicated.
func FreezeCyclicItem ¶
func FreezeCyclicItem(src *Item, opts ...cnfrt.FreezeOption) (*CatalogSnapshot, error)
FreezeCyclicItem freezes src permitting directed cycles; shared pointers are deduplicated.
func FreezeItem ¶
func FreezeItem(src *Item, opts ...cnfrt.FreezeOption) (*CatalogSnapshot, error)
FreezeItem freezes the object graph rooted at src into a snapshot. Shared pointers are deduplicated and directed cycles are rejected with cnfrt.ErrCycleDetected.
func FreezeTreeCatalog ¶
func FreezeTreeCatalog(src *Catalog, opts ...cnfrt.FreezeOption) (*CatalogSnapshot, error)
FreezeTreeCatalog freezes src as a tree: no visited set is kept (shared pointers are duplicated) and recursion deeper than the maximum depth fails with cnfrt.ErrCycleDetected. Because addresses are not recorded, src does not need to escape to the heap.
func FreezeTreeItem ¶
func FreezeTreeItem(src *Item, opts ...cnfrt.FreezeOption) (*CatalogSnapshot, error)
FreezeTreeItem freezes src as a tree: no visited set is kept (shared pointers are duplicated) and recursion deeper than the maximum depth fails with cnfrt.ErrCycleDetected. Because addresses are not recorded, src does not need to escape to the heap.
func MapCatalogFile ¶
func MapCatalogFile(path string, mode cnfrt.VerifyMode) (*CatalogSnapshot, error)
MapCatalogFile memory-maps the .cnf file at path read-only and returns a snapshot over it. With cnfrt.VerifyTrustedHeader only the header and section geometry are checked; cnfrt.VerifyChecksum also verifies all section checksums. cnfrt.VerifyUntrusted copies the file to the heap, unmaps it and validates every reference, so arbitrary input is safe to read; the returned snapshot is then not memory-mapped.
String getters of memory-mapped snapshots return copies. The mapping is released by Close or, failing that, when the snapshot becomes unreachable.
func MapItemFile ¶
func MapItemFile(path string, mode cnfrt.VerifyMode) (*CatalogSnapshot, error)
MapItemFile memory-maps the .cnf file at path read-only and returns a snapshot over it; see MapCatalogFile.
func UnmarshalCatalogSnapshot ¶
func UnmarshalCatalogSnapshot(data []byte, mode cnfrt.VerifyMode) (*CatalogSnapshot, error)
UnmarshalCatalogSnapshot decodes a .cnf image. Tables and strings of the result alias data, which must not be modified while the snapshot is in use, except with cnfrt.VerifyUntrusted, which validates an aligned private copy.
func (*CatalogSnapshot) Close ¶
func (s *CatalogSnapshot) Close() error
Close releases the memory mapping of a snapshot opened with MapCatalogFile. It is idempotent and a no-op for heap snapshots. Views of a closed snapshot panic; Close must not be called concurrently with reads.
func (*CatalogSnapshot) Cyclic ¶
func (s *CatalogSnapshot) Cyclic() bool
Cyclic reports whether the snapshot was produced by a FreezeCyclic function.
func (*CatalogSnapshot) IsMmap ¶
func (s *CatalogSnapshot) IsMmap() bool
IsMmap reports whether the snapshot is backed by a memory-mapped file.
func (*CatalogSnapshot) LenCatalog ¶
func (s *CatalogSnapshot) LenCatalog() int
LenCatalog returns the number of Catalog nodes in the snapshot.
func (*CatalogSnapshot) LenItem ¶
func (s *CatalogSnapshot) LenItem() int
LenItem returns the number of Item nodes in the snapshot.
func (*CatalogSnapshot) LenSeller ¶
func (s *CatalogSnapshot) LenSeller() int
LenSeller returns the number of Seller nodes in the snapshot.
func (*CatalogSnapshot) MarkRetired ¶
func (s *CatalogSnapshot) MarkRetired()
MarkRetired tells the leak detector, if enabled, that the snapshot is no longer expected to be referenced.
func (*CatalogSnapshot) MarshalCNF ¶
func (s *CatalogSnapshot) MarshalCNF() ([]byte, error)
MarshalCNF returns the snapshot encoded as a .cnf image. It returns cnfrt.ErrClosed if s is a closed memory-mapped snapshot, or cnfrt.ErrDictRequired if s references a process-local cnfrt.Dict.
func (*CatalogSnapshot) Root ¶
func (s *CatalogSnapshot) Root() CatalogView
Root returns the root view of the snapshot.
func (*CatalogSnapshot) RootCatalog ¶
func (s *CatalogSnapshot) RootCatalog() CatalogView
RootCatalog returns the root view if the snapshot's root is a Catalog, or the zero view.
func (*CatalogSnapshot) RootItem ¶
func (s *CatalogSnapshot) RootItem() ItemView
RootItem returns the root view if the snapshot's root is a Item, or the zero view.
func (*CatalogSnapshot) SizeBytes ¶
func (s *CatalogSnapshot) SizeBytes() int
SizeBytes returns the total size of the snapshot's tables, pools and string blob.
func (*CatalogSnapshot) UnfreezeCatalog ¶
func (s *CatalogSnapshot) UnfreezeCatalog() (*Catalog, error)
UnfreezeCatalog rebuilds the root Catalog and everything reachable from it.
func (*CatalogSnapshot) UnfreezeItem ¶
func (s *CatalogSnapshot) UnfreezeItem() (*Item, error)
UnfreezeItem rebuilds the root Item and everything reachable from it.
func (*CatalogSnapshot) UsesDict ¶
func (s *CatalogSnapshot) UsesDict() bool
UsesDict reports whether the snapshot stores any strings in a shared cnfrt.Dict.
func (*CatalogSnapshot) WithRootCatalogFaultSafe ¶
func (s *CatalogSnapshot) WithRootCatalogFaultSafe(fn func(CatalogView) error) error
WithRootCatalogFaultSafe calls fn with the Catalog root view and converts memory faults (for example from a mapped file truncated by another process) into cnfrt.ErrMmapFault.
func (*CatalogSnapshot) WithRootFaultSafe ¶
func (s *CatalogSnapshot) WithRootFaultSafe(fn func(CatalogView) error) error
WithRootFaultSafe calls fn with the root view and converts memory faults (for example from a mapped file truncated by another process) into cnfrt.ErrMmapFault.
func (*CatalogSnapshot) WithRootItemFaultSafe ¶
func (s *CatalogSnapshot) WithRootItemFaultSafe(fn func(ItemView) error) error
WithRootItemFaultSafe calls fn with the Item root view and converts memory faults (for example from a mapped file truncated by another process) into cnfrt.ErrMmapFault.
type CatalogView ¶
type CatalogView struct {
// contains filtered or unexported fields
}
CatalogView is a read-only view of a Catalog node. The zero value is the nil view; like methods on a nil pointer, its field getters panic.
func (CatalogView) AppendVersion ¶
func (v CatalogView) AppendVersion(dst []byte) []byte
AppendVersion appends the Version field to dst without an intermediate copy.
func (CatalogView) IsValid ¶
func (v CatalogView) IsValid() bool
IsValid reports whether v refers to a node.
func (CatalogView) Items ¶
func (v CatalogView) Items() Uint64ItemHashMapView
Items returns the Items field.
func (CatalogView) NodeID ¶
func (v CatalogView) NodeID() cnfrt.NodeID
NodeID returns the node's 1-based ID in its table, or 0 for the nil view.
func (CatalogView) Snapshot ¶
func (v CatalogView) Snapshot() *CatalogSnapshot
Snapshot returns the snapshot that holds the node.
func (CatalogView) Unfreeze ¶
func (v CatalogView) Unfreeze() (*Catalog, error)
Unfreeze rebuilds the node and everything reachable from it as ordinary Go values. Shared nodes and cycles are preserved.
func (CatalogView) Version ¶
func (v CatalogView) Version() string
Version returns the Version field.
func (CatalogView) VersionEquals ¶
func (v CatalogView) VersionEquals(s string) bool
VersionEquals reports whether the Version field equals s without allocating.
func (CatalogView) VersionLen ¶
func (v CatalogView) VersionLen() int
VersionLen returns the length of the Version field.
func (CatalogView) WithVersion ¶
func (v CatalogView) WithVersion(fn func(string))
WithVersion calls fn with the Version field without copying it. fn must not retain the string beyond the call (it may alias a memory-mapped file).
type CompactItem ¶
type CompactItem struct {
// contains filtered or unexported fields
}
CompactItem is a 16-byte immutable value holding a complete frozen Item in a single string, so a map or slice of CompactItem values contains one pointer per value. Scalar, string, time and address fields of the root are read directly at constant offsets without allocating; everything else is reachable through View.
Layout (slim format 0x03): a flags byte, the root's single 88-byte flat record, the string blob offset, optional dictToken / ext / seed headers, the 64-bit schema hash, a section presence bitmask, unsigned varint counts for non-empty sections, payloads ordered by descending alignment (8, 4, 2, 1), and a trailing 4-byte CRC32C.
func BorrowCompactItem ¶
func BorrowCompactItem(raw string) (CompactItem, error)
BorrowCompactItem validates the compact prefix of raw and returns a CompactItem that aliases raw without copying. It is intended for zero-copy reads inside callbacks such as SlabMap.Borrow and FrozenMap.Borrow; the returned value must not be retained beyond the lifetime of raw.
func BorrowCompactItemBytes ¶
func BorrowCompactItemBytes(raw []byte) (CompactItem, error)
BorrowCompactItemBytes is BorrowCompactItem for a byte slice, without copying. The returned CompactItem aliases raw: it is valid only while raw is neither modified nor reused, typically for the duration of a SlabMap.Borrow callback, and must not be retained beyond it. Use ParseCompactItem on a copy to keep a value.
func PackCyclicItem ¶
func PackCyclicItem(src *Item, opts ...cnfrt.FreezeOption) (CompactItem, error)
PackCyclicItem freezes src permitting directed cycles (as FreezeCyclicItem does) into a CompactItem.
func PackItem ¶
func PackItem(src *Item, opts ...cnfrt.FreezeOption) (CompactItem, error)
PackItem freezes src (as FreezeItem does) into a CompactItem.
func PackTreeItem ¶
func PackTreeItem(src *Item, opts ...cnfrt.FreezeOption) (CompactItem, error)
PackTreeItem freezes src as a tree (as FreezeTreeItem does) into a CompactItem.
func ParseCompactItem ¶
func ParseCompactItem(raw string, mode cnfrt.VerifyMode, opts ...cnfrt.ParseOption) (CompactItem, error)
ParseCompactItem checks raw (as produced by Raw) and returns it as a CompactItem. The embedded image is verified according to mode. With cnfrt.VerifyUntrusted a value that references a cnfrt.Dict is rejected with cnfrt.ErrDictRequired unless that Dict is passed with cnfrt.AllowDict.
func (CompactItem) Active ¶
func (c CompactItem) Active() bool
Active returns the Active field of the root without allocating.
func (CompactItem) AppendCNF ¶
func (c CompactItem) AppendCNF(dst []byte) []byte
AppendCNF implements cnfrt.SelfCodec.
func (CompactItem) CodecCNF ¶
func (CompactItem) CodecCNF() cnfrt.Codec[CompactItem]
CodecCNF implements cnfrt.CodecProvider. Maps such as cnfrt.FrozenMap and cnfrt.SlabMap use the returned codec for CompactItem values by default.
func (*CompactItem) DecodeCNF ¶
func (c *CompactItem) DecodeCNF(src string) error
DecodeCNF implements cnfrt.SelfDecoder. It checks the compact prefix; use ParseCompactItem to verify the embedded image as well. src is retained.
func (CompactItem) Detach ¶
func (c CompactItem) Detach(opts ...cnfrt.FreezeOption) (CompactItem, error)
Detach returns a self-contained CompactItem with all dictionary strings materialized into its local string blob. If c does not use a dictionary, Detach returns c. By default the result keeps the hash seed of c (DefaultSeed unless c carries an explicit seed) and time.Local, so detaching the same value twice yields identical bytes; caller opts override those defaults except that WithDict is always cleared so the result never references a cnfrt.Dict. It returns cnfrt.ErrUnknownDict if the dictionary of c has been closed.
func (CompactItem) Equal ¶
func (c CompactItem) Equal(o CompactItem) bool
Equal reports whether c and o hold identical encodings.
func (CompactItem) ID ¶
func (c CompactItem) ID() uint64
ID returns the ID field of the root without allocating.
func (CompactItem) IsZero ¶
func (c CompactItem) IsZero() bool
IsZero reports whether c is the zero value.
func (CompactItem) Price ¶
func (c CompactItem) Price() int64
Price returns the Price field of the root without allocating.
func (CompactItem) Raw ¶
func (c CompactItem) Raw() string
Raw returns the encoded value. It can be stored and later passed to ParseCompactItem.
func (CompactItem) SKU ¶
func (c CompactItem) SKU() string
SKU returns the SKU field of the root without allocating.
func (CompactItem) SKUEquals ¶
func (c CompactItem) SKUEquals(v string) bool
SKUEquals reports whether the SKU field equals v without allocating.
func (CompactItem) SKULen ¶
func (c CompactItem) SKULen() int
SKULen returns the length of the SKU field without allocating.
func (CompactItem) SchemaHashCNF ¶
func (CompactItem) SchemaHashCNF() uint64
SchemaHashCNF implements cnfrt.SchemaHasher.
func (CompactItem) Snapshot ¶
func (c CompactItem) Snapshot(mode cnfrt.VerifyMode, opts ...cnfrt.ParseOption) (*CatalogSnapshot, error)
Snapshot loads the embedded image as a snapshot, verified according to mode; see ParseCompactItem for the options.
func (CompactItem) Stock ¶
func (c CompactItem) Stock() int32
Stock returns the Stock field of the root without allocating.
func (CompactItem) Title ¶
func (c CompactItem) Title() string
Title returns the Title field of the root without allocating.
func (CompactItem) TitleEquals ¶
func (c CompactItem) TitleEquals(v string) bool
TitleEquals reports whether the Title field equals v without allocating.
func (CompactItem) TitleLen ¶
func (c CompactItem) TitleLen() int
TitleLen returns the length of the Title field without allocating.
func (CompactItem) TryView ¶
func (c CompactItem) TryView() (ItemView, error)
TryView is like View but returns an error instead of panicking: cnfrt.ErrUnknownDict if c references a closed cnfrt.Dict, or a header error if c is corrupt.
func (CompactItem) Unpack ¶
func (c CompactItem) Unpack() (*Item, error)
Unpack rebuilds the original Item. It returns cnfrt.ErrUnknownDict if c references a closed cnfrt.Dict.
func (CompactItem) Updated ¶
func (c CompactItem) Updated() time.Time
Updated returns the Updated field of the root without allocating.
func (CompactItem) UsesDict ¶
func (c CompactItem) UsesDict() bool
UsesDict reports whether c stores any strings in a process-local cnfrt.Dict.
func (CompactItem) View ¶
func (c CompactItem) View() ItemView
View returns a view of the root over the embedded image. The image is not copied, but a snapshot header is allocated; the direct getters of CompactItem do not allocate. View panics if c is corrupt or references a closed cnfrt.Dict (use TryView to get an error instead), and returns the zero view for the zero value.
type CompactStore ¶
type CompactStore struct{ M map[uint64]CompactItem }
CompactStore keeps one Compact value per item in a Go map.
type DimsView ¶
type DimsView struct {
// contains filtered or unexported fields
}
DimsView is a read-only view of an inline Dims value.
func (DimsView) Snapshot ¶
func (v DimsView) Snapshot() *CatalogSnapshot
Snapshot returns the snapshot that holds the value.
type FreezeCost ¶
type FreezeCost struct {
N int
Time time.Duration
Allocated uint64 // bytes allocated during Freeze
Allocs uint64 // heap objects allocated during Freeze
// Peak is the highest heap occupancy observed during Freeze above the
// occupancy before it (with the source catalog alive), sampled from
// /memory/classes/heap/objects:bytes every 20µs.
Peak uint64
Tables int // size of the resulting snapshot tables and strings
}
FreezeCost measures FreezeCatalog for a catalog of n items.
func MeasureFreeze ¶
func MeasureFreeze(n int) (FreezeCost, error)
MeasureFreeze freezes a catalog of n items and reports its cost.
type Item ¶
type Item struct {
ID uint64
SKU string
Title string
Price int64
Stock int32
Active bool
Tags []string
Attrs map[string]string
Updated time.Time
Dims Dims
Seller *Seller
}
Item is one catalog entry.
type ItemView ¶
type ItemView struct {
// contains filtered or unexported fields
}
ItemView is a read-only view of a Item node. The zero value is the nil view; like methods on a nil pointer, its field getters panic.
func (ItemView) AppendTitle ¶
AppendTitle appends the Title field to dst without an intermediate copy.
func (ItemView) Attrs ¶
func (v ItemView) Attrs() StringStringMapView
Attrs returns the Attrs field.
func (ItemView) Snapshot ¶
func (v ItemView) Snapshot() *CatalogSnapshot
Snapshot returns the snapshot that holds the node.
func (ItemView) TitleEquals ¶
TitleEquals reports whether the Title field equals s without allocating.
func (ItemView) Unfreeze ¶
Unfreeze rebuilds the node and everything reachable from it as ordinary Go values. Shared nodes and cycles are preserved.
type Result ¶
type Result struct {
Scenario string
N int
// Build is the time to construct the store from the native catalog;
// it is zero for the native scenarios, whose store is the catalog.
Build time.Duration
// Heap is the live heap attributable to the store, from
// /memory/classes/heap/objects:bytes after a full collection. Stores
// built from the catalog are measured after the catalog is released.
Heap uint64
// OffHeap is memory held outside the Go heap (a file mapping).
OffHeap uint64
// Scan is /gc/scan/heap:bytes, the heap the collector scanned in the
// last cycle, minus the baseline before the store was built.
Scan uint64
// FullGC is the median duration of five forced collections.
FullGC time.Duration
// Read is the mean cost of one random point read.
Read time.Duration
// Churn measures a workload that allocates short-lived objects while
// the store is alive.
ChurnWall time.Duration
ChurnGCs uint64
ChurnGCCPU time.Duration
}
Result holds the measurements of one scenario.
type SellerView ¶
type SellerView struct {
// contains filtered or unexported fields
}
SellerView is a read-only view of a Seller node. The zero value is the nil view; like methods on a nil pointer, its field getters panic.
func (SellerView) AppendCountry ¶
func (v SellerView) AppendCountry(dst []byte) []byte
AppendCountry appends the Country field to dst without an intermediate copy.
func (SellerView) AppendName ¶
func (v SellerView) AppendName(dst []byte) []byte
AppendName appends the Name field to dst without an intermediate copy.
func (SellerView) CountryEquals ¶
func (v SellerView) CountryEquals(s string) bool
CountryEquals reports whether the Country field equals s without allocating.
func (SellerView) CountryLen ¶
func (v SellerView) CountryLen() int
CountryLen returns the length of the Country field.
func (SellerView) IsValid ¶
func (v SellerView) IsValid() bool
IsValid reports whether v refers to a node.
func (SellerView) NameEquals ¶
func (v SellerView) NameEquals(s string) bool
NameEquals reports whether the Name field equals s without allocating.
func (SellerView) NameLen ¶
func (v SellerView) NameLen() int
NameLen returns the length of the Name field.
func (SellerView) NodeID ¶
func (v SellerView) NodeID() cnfrt.NodeID
NodeID returns the node's 1-based ID in its table, or 0 for the nil view.
func (SellerView) Snapshot ¶
func (v SellerView) Snapshot() *CatalogSnapshot
Snapshot returns the snapshot that holds the node.
func (SellerView) Unfreeze ¶
func (v SellerView) Unfreeze() (*Seller, error)
Unfreeze rebuilds the node and everything reachable from it as ordinary Go values. Shared nodes and cycles are preserved.
func (SellerView) WithCountry ¶
func (v SellerView) WithCountry(fn func(string))
WithCountry calls fn with the Country field without copying it. fn must not retain the string beyond the call (it may alias a memory-mapped file).
func (SellerView) WithName ¶
func (v SellerView) WithName(fn func(string))
WithName calls fn with the Name field without copying it. fn must not retain the string beyond the call (it may alias a memory-mapped file).
type SlabBorrowStore ¶
type SlabBorrowStore struct {
M *cnfrt.SlabMap[uint64, CompactItem]
}
SlabBorrowStore keeps Compact values in a cnfrt.SlabMap and reads zero-copy via Borrow and BorrowCompactItemBytes.
type SlabStore ¶
type SlabStore struct {
M *cnfrt.SlabMap[uint64, CompactItem]
}
SlabStore keeps Compact values in a cnfrt.SlabMap and reads via Get (copying).
type SnapshotStore ¶
type SnapshotStore struct{ S *CatalogSnapshot }
SnapshotStore reads through a frozen catalog.
type Store ¶
type Store interface {
// Read returns the price and a byte-derived digest of the title of the
// item with the given ID. Every implementation touches the title bytes
// symmetrically.
Read(id uint64) (price int64, titleMetric int, ok bool)
}
Store is a read-only item cache under measurement.
type StringSliceView ¶
type StringSliceView struct {
// contains filtered or unexported fields
}
StringSliceView is a read-only view of a slice of string. It has no function-valued fields, so ranging over All does not allocate.
func (StringSliceView) All ¶
func (s StringSliceView) All() iter.Seq[string]
All returns an iterator over the elements.
func (StringSliceView) At ¶
func (s StringSliceView) At(i int) string
At returns element i. It panics if i is out of range.
func (StringSliceView) EqualsAt ¶
func (s StringSliceView) EqualsAt(i int, str string) bool
EqualsAt reports whether element i equals str without allocating.
func (StringSliceView) IsNil ¶
func (s StringSliceView) IsNil() bool
IsNil reports whether the slice is nil.
type StringStringMapView ¶
type StringStringMapView struct {
// contains filtered or unexported fields
}
StringStringMapView is a read-only view of a map[string]string.
func (StringStringMapView) All ¶
func (m StringStringMapView) All() iter.Seq2[string, string]
All returns an iterator over the entries in ascending key order.
func (StringStringMapView) Get ¶
func (m StringStringMapView) Get(k string) (string, bool)
Get returns the value stored for k.
func (StringStringMapView) IsNil ¶
func (m StringStringMapView) IsNil() bool
IsNil reports whether the map is nil.
func (StringStringMapView) Keys ¶
func (m StringStringMapView) Keys() iter.Seq[string]
Keys returns an iterator over the keys in ascending order.
func (StringStringMapView) Len ¶
func (m StringStringMapView) Len() int
Len returns the number of entries.
type Uint64ItemHashMapView ¶
type Uint64ItemHashMapView struct {
// contains filtered or unexported fields
}
Uint64ItemHashMapView is a read-only view of a map[uint64]*Item.
func (Uint64ItemHashMapView) All ¶
func (m Uint64ItemHashMapView) All() iter.Seq2[uint64, ItemView]
All returns an iterator over the entries in ascending key order.
func (Uint64ItemHashMapView) Get ¶
func (m Uint64ItemHashMapView) Get(k uint64) (ItemView, bool)
Get returns the value stored for k.
func (Uint64ItemHashMapView) IsNil ¶
func (m Uint64ItemHashMapView) IsNil() bool
IsNil reports whether the map is nil.
func (Uint64ItemHashMapView) Keys ¶
func (m Uint64ItemHashMapView) Keys() iter.Seq[uint64]
Keys returns an iterator over the keys in ascending order.
func (Uint64ItemHashMapView) Len ¶
func (m Uint64ItemHashMapView) Len() int
Len returns the number of entries.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
report
command
Command report runs every benchmark scenario of package benchmarks in a fresh child process, so that heap measurements do not interfere, and prints the results as Markdown tables.
|
Command report runs every benchmark scenario of package benchmarks in a fresh child process, so that heap measurements do not interfere, and prints the results as Markdown tables. |