benchmarks

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 24 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const ChurnBytes = 2 << 30

ChurnBytes is the default volume of garbage allocated by the churn workload.

View Source
const NumSellers = 1000

NumSellers is the number of distinct sellers in a generated catalog.

View Source
const SchemaHashCatalog uint64 = 0x474aabe8286f5679

SchemaHashCatalog identifies the layout of CatalogSnapshot images.

Variables

View Source
var ColdStarts = []string{"json", "gob", "cnf-trusted", "cnf-checksum", "cnf-untrusted"}

ColdStarts lists the formats accepted by ColdStart.

View Source
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.

View Source
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

func ColdStart(format, dir string, probe uint64) (time.Duration, int64, error)

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

func WriteColdStartFiles(n int, dir string) error

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

type Catalog struct {
	Version string
	Items   map[uint64]*Item `cnf:",hash"`
}

Catalog is a product catalog indexed by item ID.

func MakeCatalog

func MakeCatalog(n int) *Catalog

MakeCatalog returns a deterministic catalog of n items with IDs 1..n.

func MakeHighCardCatalog

func MakeHighCardCatalog(n int) *Catalog

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

func MakeInternedCatalog(n int) *Catalog

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.

func (*CatalogSnapshot) WriteTo

func (s *CatalogSnapshot) WriteTo(w io.Writer) (int64, error)

WriteTo writes the snapshot as a .cnf image to w. It returns cnfrt.ErrClosed if s is a closed memory-mapped snapshot, or cnfrt.ErrDictRequired if s references a process-local cnfrt.Dict.

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

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) SizeCNF

func (c CompactItem) SizeCNF() int

SizeCNF implements cnfrt.SelfCodec.

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.

func (CompactStore) Read

func (s CompactStore) Read(id uint64) (int64, int, bool)

Read implements Store.

type Dims

type Dims struct {
	W, H, D float32
}

Dims are package dimensions in centimetres.

type DimsView

type DimsView struct {
	// contains filtered or unexported fields
}

DimsView is a read-only view of an inline Dims value.

func (DimsView) D

func (v DimsView) D() float32

D returns the D field.

func (DimsView) H

func (v DimsView) H() float32

H returns the H field.

func (DimsView) IsValid

func (v DimsView) IsValid() bool

IsValid reports whether v refers to a value in a snapshot.

func (DimsView) Snapshot

func (v DimsView) Snapshot() *CatalogSnapshot

Snapshot returns the snapshot that holds the value.

func (DimsView) Unfreeze

func (v DimsView) Unfreeze() (*Dims, error)

Unfreeze rebuilds the value and everything reachable from it as ordinary Go values.

func (DimsView) W

func (v DimsView) W() float32

W returns the W field.

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.

func MakeItem

func MakeItem(id uint64, seller *Seller) *Item

MakeItem returns the item with the given ID.

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) Active

func (v ItemView) Active() bool

Active returns the Active field.

func (ItemView) AppendSKU

func (v ItemView) AppendSKU(dst []byte) []byte

AppendSKU appends the SKU field to dst without an intermediate copy.

func (ItemView) AppendTitle

func (v ItemView) AppendTitle(dst []byte) []byte

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) Dims

func (v ItemView) Dims() DimsView

Dims returns the Dims field.

func (ItemView) ID

func (v ItemView) ID() uint64

ID returns the ID field.

func (ItemView) IsValid

func (v ItemView) IsValid() bool

IsValid reports whether v refers to a node.

func (ItemView) NodeID

func (v ItemView) NodeID() cnfrt.NodeID

NodeID returns the node's 1-based ID in its table, or 0 for the nil view.

func (ItemView) Price

func (v ItemView) Price() int64

Price returns the Price field.

func (ItemView) SKU

func (v ItemView) SKU() string

SKU returns the SKU field.

func (ItemView) SKUEquals

func (v ItemView) SKUEquals(s string) bool

SKUEquals reports whether the SKU field equals s without allocating.

func (ItemView) SKULen

func (v ItemView) SKULen() int

SKULen returns the length of the SKU field.

func (ItemView) Seller

func (v ItemView) Seller() SellerView

Seller returns the Seller field.

func (ItemView) Snapshot

func (v ItemView) Snapshot() *CatalogSnapshot

Snapshot returns the snapshot that holds the node.

func (ItemView) Stock

func (v ItemView) Stock() int32

Stock returns the Stock field.

func (ItemView) Tags

func (v ItemView) Tags() StringSliceView

Tags returns the Tags field.

func (ItemView) Title

func (v ItemView) Title() string

Title returns the Title field.

func (ItemView) TitleEquals

func (v ItemView) TitleEquals(s string) bool

TitleEquals reports whether the Title field equals s without allocating.

func (ItemView) TitleLen

func (v ItemView) TitleLen() int

TitleLen returns the length of the Title field.

func (ItemView) Unfreeze

func (v ItemView) Unfreeze() (*Item, error)

Unfreeze rebuilds the node and everything reachable from it as ordinary Go values. Shared nodes and cycles are preserved.

func (ItemView) Updated

func (v ItemView) Updated() time.Time

Updated returns the Updated field.

func (ItemView) WithSKU

func (v ItemView) WithSKU(fn func(string))

WithSKU calls fn with the SKU field without copying it. fn must not retain the string beyond the call (it may alias a memory-mapped file).

func (ItemView) WithTitle

func (v ItemView) WithTitle(fn func(string))

WithTitle calls fn with the Title field without copying it. fn must not retain the string beyond the call (it may alias a memory-mapped file).

type NativeStore

type NativeStore struct{ C *Catalog }

NativeStore keeps ordinary Go objects.

func (NativeStore) Read

func (s NativeStore) Read(id uint64) (int64, int, bool)

Read implements Store.

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.

func Run

func Run(scenario string, n int, churnBytes int64, dir string) (Result, error)

Run builds the store of the named scenario from a catalog of n items and measures it; the churn workload allocates churnBytes. dir holds temporary files. Measurements are only meaningful in a process that runs nothing else, which is how cmd/report invokes it.

func RunHighCard

func RunHighCard(scenario string, n int, churnBytes int64, dir string) (Result, error)

RunHighCard is like Run, but uses MakeHighCardCatalog so that every item's Title and SKU are 100% distinct across all n items.

type Seller

type Seller struct {
	ID      uint32
	Name    string
	Country string
}

Seller is shared by many items.

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) Country

func (v SellerView) Country() string

Country returns the Country field.

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) ID

func (v SellerView) ID() uint32

ID returns the ID field.

func (SellerView) IsValid

func (v SellerView) IsValid() bool

IsValid reports whether v refers to a node.

func (SellerView) Name

func (v SellerView) Name() string

Name returns the Name field.

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.

func (SlabBorrowStore) Read

func (s SlabBorrowStore) Read(id uint64) (int64, int, bool)

Read implements Store.

type SlabStore

type SlabStore struct {
	M *cnfrt.SlabMap[uint64, CompactItem]
}

SlabStore keeps Compact values in a cnfrt.SlabMap and reads via Get (copying).

func (SlabStore) Read

func (s SlabStore) Read(id uint64) (int64, int, bool)

Read implements Store.

type SnapshotStore

type SnapshotStore struct{ S *CatalogSnapshot }

SnapshotStore reads through a frozen catalog.

func (SnapshotStore) Read

func (s SnapshotStore) Read(id uint64) (int64, int, bool)

Read implements Store.

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.

func (StringSliceView) Len

func (s StringSliceView) Len() int

Len returns the number of elements.

type StringStringMapView

type StringStringMapView struct {
	// contains filtered or unexported fields
}

StringStringMapView is a read-only view of a map[string]string.

func (StringStringMapView) All

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

All returns an iterator over the entries in ascending key order.

func (Uint64ItemHashMapView) Get

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL