Skip to content

Latest commit

 

History

History
113 lines (70 loc) · 5.69 KB

Index.md

File metadata and controls

113 lines (70 loc) · 5.69 KB

FastData

FastData generates data-dependent lookup code for static, read-only datasets. Because the complete key set is known before the generated code runs, FastData spends time on analysis and emits a specialized structure instead of a general-purpose runtime collection.

The primary query shapes are:

  • Membership: Returns whether a key exists.
  • Key/value lookup: Maps a key to a value.

Compatible structures can additionally expose enumeration and direct contiguous access when requested through RequiredCapability. Approximate membership must be enabled explicitly.

Data types

FastData supports two key families: numeric keys and string keys.

Numeric key generation supports these key types:

  • sbyte, byte
  • short, ushort
  • int, uint
  • long, ulong
  • char
  • float, double

Floating-point keys must be finite. NaN, positive infinity, and negative infinity are rejected during validation because exact generated lookup code cannot treat them as ordinary ordered keys.

String key generation supports string keys. String lookups are ordinal by default. IgnoreCase enables ordinal-ignore-case matching for ASCII string key sets; non-ASCII keys are rejected when it is enabled.

Key/value generation supports a value array alongside the key array. Value support depends on the selected target-language generator because values must be representable as generated source literals or generated data in that language.

Pipeline

The high-level generation pipeline is:

  1. Validate input keys and optional values.
  2. Deduplicate keys.
  3. Analyze key properties.
  4. Select a structure, unless the caller forced one.
  5. Build any structure-specific data, such as hash tables or bit vectors.
  6. Generate early-exit checks from the analyzed properties.
  7. Create a generator context for the selected structure.
  8. Lower the structure context to portable IR and render language-specific source code.

The public entry point is FastDataGenerator.

Analysis

Numeric keys analysis

  • Minimum and maximum values.
  • Sorted ranges and number of ranges.
  • Value density across the observed range.
  • Whether zero appears in the dataset.
  • Missing-bit masks used by early exits.

See Analyzer for file loading, prepared-input contracts, statistics, model selection, segmentation, and integer region merging.

String keys analysis

  • Minimum and maximum character length.
  • Length ranges and whether lengths are unique.
  • Character classes and ASCII compatibility.
  • First-character and last-character distributions.

When string hash analysis is enabled, FastData evaluates collisions across the actual key set. Unless timing is disabled, it also times candidate hash evaluation on the encoded key at the middle dataset index.

Early exits

Early exits are cheap checks emitted before the main lookup. They reject impossible keys quickly, such as strings with missing lengths or numbers outside the observed range.

See EarlyExits.md for details.

Data structures

FastData selects a lookup structure from the analyzed shape of the key set. Dense integral ranges might use compact range or bit-set structures, while other datasets can use conditional branches, succinct integral encodings, or hash-based structures. Binary search and linear arrays remain available explicitly or as fallbacks when earlier choices are disabled or incompatible. String data can also use length-based structures or hash strategies when those are a better fit.

The selected structure determines the data stored in the generated code and the final lookup path after early exits have run. Users can let FastData choose automatically or force a structure through configuration when they know which tradeoff they want.

See DataStructures.md for details.

Hashing

Hashing is used when a hash-based structure is the best fit for the analyzed key set. For strings, FastData evaluates candidate collisions across the actual keys and can time representative hash evaluations to choose a strategy for the generated lookup.

Hashing decisions are still compile-time work: the generated code only contains the selected hash calculation and the prepared lookup data needed by the chosen structure.

See Hashing.md for details.

Expression compilation

Hash functions and early exits are constructed directly in typed portable IR and rendered by the C#, C++20, or Rust backend. See expression compilation, the IR migration guide, and the guide to verifying IR optimizations.

See ExpressionCompilation.md for the lowering boundary and extension rules.

Misc

Performance optimizations

FastData performs several compile-time and generated-code optimizations, including structure selection, early exits, expression simplification, branch-shape choices, compact table layouts, and arithmetic reductions. These optimizations aim to move expensive decisions into generation time while keeping runtime lookup code small and predictable.

See Optimizations.md for details.

Compile-time benefits

Generating the structure ahead of time provides several benefits:

  • Data can be compiled into the consuming program.
  • Expensive analysis has zero runtime cost.
  • The generated code avoids defensive copying and runtime collection initialization.
  • Calls can avoid virtual dispatch and unnecessary branching.
  • Modulo by known constants can be optimized by the compiler.
  • Internal tables can use smaller integer types when the data range allows it.
  • String data can use the target language's most efficient representation.