Skip to content

v3.0.0

Compare
Choose a tag to compare
@stephenberry stephenberry released this 16 Jul 14:32
· 512 commits to main since this release

Glaze 3.0.0

This release brings core architecture improvements along with breaking changes to improve compile time and runtime performance.

Moving to C++23

While this release still builds with C++20, Glaze will begin using more C++23 features in version 3. All compilers that currently build Glaze already have C++23 modes, so if you could build the code before you should be able to change the version to C++23 without issue. This release does not reduce the current supported compiler versions.

Why require C++23? The core architecture can be cleaned up and result in faster compile times via the use of static constexpr within constexpr functions. More constexpr support, resize_and_overwrite, and std::flat_map will also bring performance improvements to various parts of Glaze.

Breaking Changes

Removed glz::schema support in glz::object

template <> struct glz::meta<my_struct> {
  static constexpr auto value = object("i", &my_struct::i, schema{.description = "i is an integer"}); // schema is no longer allowed here
};

Cleaner JSON Schema metadata has been supported for a while with the improved glz::json_schema approach:

template <> struct glz::json_schema<my_struct> {
   schema i{.description = "i is an integer"};
};

Use this decoupled approach in version 3. The old approach was slower to compile and didn't cleanly separate the normal reflection metadata from JSON schema logic. The older approach was also harder to read when dealing with lots of JSON Schema metadata.

Removed Machine Generated Comments in glz::object

Comments do not conform to the core JSON specification. They were also difficult to roundtrip, and machine generated comments are not as useful for human interaction because humans like putting comments is less ideal places and with // syntax rather than the /**/ syntax that can be minified.

template <> struct glz::meta<my_struct> {
  static constexpr auto value = object("i", &my_struct::i, "old comment"_c); // The comment here is no longer allowed
};

Now that we have more robust JSON schema support, we have found this to be a better solution to machine generated comments in JSON using tools like Visual Studio Code.

  • Reading comments via the JSONC syntax is still supported. So, humans can still add comments to input files. Use the .comments = true option when reading.
  • This change improves compile times.

Escaped keys must be registered in escaped form (for glz::object)

For backslashes \ and quotes ", which need to be escaped in JSON, the user must now register the escaped forms of these keys with glz::object. It is not common, nor recommended to have escaped characters in JSON keys, but this improves the performance of handling these keys.

struct Escaped {
   int escaped_key{};
   std::string escaped_key2{"hi"};
};

template <> struct glz::meta<Escaped> {
   using T = Escaped;
   static constexpr auto value = object(R"(escaped\"key)", &T::escaped_key,
                                        R"(escaped\"\"key2)", &T::escaped_key2);
};

New Option: escaped_unicode_key_conversion

The default behavior for escaped unicode \u... has been changed. The JSON specification does not require escaped and unescaped unicode keys to match. To improve performance, especially for foreign languages, the default behavior in Glaze will not automatically convert escaped unicode to unescaped unicode.

If you desire escaped unicode \u... keys to match with unescaped unicode then enable the new option: .escaped_unicode_key_conversion = true

It is recommended to use unescaped UTF-8 for keys, as it is much faster for reading/writing and typically easier to work with for developers. Unescaped unicode lets you see the characters wherever UTF-8 is supported, e.g. 😀😃😄💐🌹🥀🌺🌷🌸💮🏵️🌻🌼

Removed glz::poly and the supporting glz::any

glz::poly was an experiment in polymorphism without inheritance that Glaze did not use anywhere. It was an neat proof of concept, but we've since discovered better approaches to static polymorphism which we intend to add to Glaze. These newer approaches result in faster runtimes, cleaner code, faster compilation, and easier debugging.

Improvements

New Hash Maps

More advanced and faster hash maps.

Glaze adds a new core mechanism for compile time perfect hashing. This approach eliminates the use of std::variant and directly builds jump tables. Key comparisons are now embedded at the call site and in many cases with compile time known keys we can avoid the key parsing step by jumping to a direct comparison. Many times a single character lookup can be used as the hashing algorithm as Glaze will search at compile time for a unique character column among keys to build extremely efficient hash tables.

Additional Improvements

  • Removed extra template/function instantiations due to unnecessary indirections. This makes debugging easier as well.

Full Changelog: v2.9.5...v3.0.0