github stephenberry/glaze v7.0.1

latest releases: v9.0.0, v8.4.0, v8.3.0...
9 months ago

Glaze v7.0.1

Highlights

  • Reduced binary size for embedded and size-constrained environments (use glz::size_opts and GLZ_DISABLE_ALWAYS_INLINE)
  • TOML support for std::variant and generic types (glz::generic, maps)
  • Optimized floating-point parsing
  • Fixed sparse enums with large values (#2246)

Binary Size Optimization

This release focuses heavily on reducing binary size for embedded systems and size-constrained environments.

std::error_code Integration Moved to Optional Header

The unused std::error_code integration has been moved from the core headers to a separate optional header:

#include <glaze/core/std_error_code.hpp>

This reduces binary size by ~34KB for users who don't need std::error_code compatibility. The overhead came from the global error_category variable with std::error_category vtable, which forced a DATA segment with page alignment overhead.

Breaking Change: If your code uses glz::error_category, glz::make_error_code(), or relies on implicit conversion from glz::error_code to std::error_code, you must now explicitly include the header:

#include <glaze/core/std_error_code.hpp>

Size-Optimized Float Parsing (simple_float.hpp)

A new compact floating-point parsing and serialization module achieves ~21-25KB savings compared to the full dragonbox/fast_float implementations:

  • Maintains strict JSON compliance
  • Verified to roundtrip with all of Glaze's floating point algorithms, so no changes occur when switching from glz::opts_size and peak performance algorithms

This is automatically used when serializing/deserializing with glz::opts_size.


TOML Improvements

Variant and Generic Type Support (#2240)

Full TOML serialization support for:

  • std::variant types with automatic type detection
  • Generic types: glz::generic, glz::generic_i64, glz::generic_u64
  • Map types: std::map, std::unordered_map
std::variant<int, double, std::string> value = 3.14;
std::string toml;
glz::write<glz::TOML>(value, toml);
// toml: "3.14"

Features:

  • Automatic type detection from TOML syntax (quoted strings, booleans, arrays, objects, floats, integers)
  • Dotted keys and table sections within map contexts
  • Path-based nested map navigation for type safety

Bug Fixes

Sparse Enums with Large Values (#2246)

Fixed compilation failure for enums with values that share common power-of-2 factors:

enum class SparseEnum : int {
   Zero = 0,
   FourHundredMillion = 400000000  // Previously failed to compile
};

The issue occurred because values like 0 and 400000000 (both divisible by 2^10) would hash to the same bucket with standard modular hashing, causing "Failed to find perfect hash seed for enum" errors.

Solution: Added a new modular_shifted hash strategy that removes common trailing zeros before hashing. The compiler automatically selects this strategy when standard modular hashing fails.


Pull Requests

  • #2246 - Fix sparse enums with large values (modular_shifted hash)
  • #2245 - Reduce binary size (std_error_code.hpp, template bifurcation)
  • #2244 - Optimized digit parsing
  • #2241 - Small binary simple_float for size optimization level
  • #2240 - Generic TOML support and variant handling

Don't miss a new glaze release

NewReleases is sending notifications on new releases.