Flecs 3.0 is out!

Sander Mertens
8 min readAug 2, 2022

What is Flecs?

Flecs is an Entity Component System (FAQ) for C and C++ that helps with building games, simulations and more. The core features of Flecs are:

  • Store data for millions of entities in data structures optimized for CPU cache efficiency and composition-first design
  • Find entities for game systems with a high performance query engine that can run in time critical game loops
  • Run code using a multithreaded scheduler that seamlessly combines game systems from reusable modules
  • Builtin support for hierarchies, prefabs and more with entity relationships which speed up game code and reduce boiler plate
  • An ecosystem of tools to profile, visualize, document and debug projects

Flecs is fully open source and licensed under the MIT license. Check out the Github repository here:

Link to the v3 release:

What happened?

Flecs 3 just got released and a lot has changed! Here’s a summary:

  • Almost a 1000 new commits got added with the repository now having more than 3000 commits in total
  • More than 100 issues and PRs submitted by dozens of community members got closed and merged ❤️
  • The Flecs Discord server almost doubled in size and now has over a 1000 members
  • The number of GitHub stars more than doubled from 1300 to almost 2900
  • The number of test cases grew from 2600 to 4400, with the amount of test code growing from 71K to 130K lines of code
  • There are now 4 community supported and actively developed language bindings for Lua, C#, Zig and Rust

Who is using Flecs?

Flecs is used in a wide range of projects, from small web-based games to RPGs to sprawling universe simulators. Projects are built with existing engines like Unreal, Godot and Unity, as well as brand new engines that use Vulkan, OpenGL, bgfx, sokol and SDL. Some projects aren’t games at all, and use Flecs as a fast in-memory database.

Here is one particularly cool project that recently adopted Flecs:

https://github.com/ConfettiFX/The-Forge

The Forge is a cross-platform rendering framework that has contributed to many AAA game titles such as Tomb Raider, Battlefield 4, Murdered: Soul Suspect, Star Citizen, Dirt 4, Vainglory, Transistor, Call of Duty: Black Ops III, Battlefield 1, Mafia III and Bethesda’s Starfield. [source, source].

In December last year The Forge replaced their home-grown ECS with Flecs which improved performance by 2–5x! [source]

To see more projects that use Flecs, see the README. Also consider checking out the #showcase channel in the Flecs Discord to stay up to date on the latest games in development with Flecs!

Release Highlights

A full list of all changes would be way too long, so here is a summary of the biggest changes since the last release:

  • Entity Relationships. While first introduced in v2.4.8, this release is a huge step forward. Relationships in Flecs 3 are faster, more stable, have more features and are easier to use than ever (blog).
  • Flecs Explorer. The Explorer is a brand new Flecs 3 tool for inspecting running apps, profile systems, trying out Flecs features and much more. Click here to try it out.
Features of the Flecs Explorer
  • City Demo. A new demo has been created that showcases many Flecs 3 features and is built with flecs hub modules. The demo runs on all major platforms, including the browser: https://flecs.dev/city.
Screenshot of the city demo
  • Reflection. Flecs 3 comes with an optional reflection addon that is designed from scratch to integrate with scripting languages, other game engines and reflection frameworks like RTTI or Cereal. Reflection data is created at runtime and stored in the ECS using regular entities and components.
  • New Scheduler. Flecs 3 has a new default scheduler that uses a dependency tree to order systems. In addition the pipeline addon now makes it possible for apps to specify a custom systems query, which allows for full customization of which systems get matched by a schedule, and which ordering algorithm to use.
  • Query & Observer Unification. Flecs 3 uses a single query engine for both queries and observers. This means that apps can now use the full expressiveness of Flecs queries when observing events, while being assured that both mechanism match exactly the same entities.
  • New AI Inspired Query Engine. Flecs 3 extends the query engine with an experimental new constraint solver that is inspired by Artificial Intelligence tools like Prolog. The new engine can efficiently match complex patterns across entity relationships, bringing AI technology one step closer to realtime gaming (examples).
  • App Framework. Flecs 3 has a new optional app addon that manages the main loop. This can be used to hide platform specific details about how the main loop is ran, like how a browser takes control of the main loop in webasm apps. Overridable hooks allow modules such as a renderer to inject custom logic (example).
  • Monitoring. A new monitor module tracks metrics from the existing statistics addon over time periods ranging from one second to one week. Metrics are stored in components, and can be inspected with the regular ECS API or with the performance dashboards of Flecs Explorer:
Monitoring metrics in the Flecs Explorer
  • Scene DSL. Flecs 3 has a new text-based format for loading entities and components into the ECS. The format integrates with features like relationships and reflection, and can be used for things like configuration files, scene descriptions and assets (example).
  • Enum Relationships. The C++ API now allows for adding enumeration constants directly to entities. Constants are added as relationships, which makes them queryable. Enumerations do not have to be registered in advance. An example:
enum Color { Red, Green, Blue };// create entity with (Color, Color::Red)
flecs::entity e = world.entity()
.add(Color::Red);
  • New C99 Descriptor APIs. The new C99 descriptor APIs now support a new notation that reduces the amount of boiler plate. The old notation is still supported. An example:
// Old
ecs_filter_t *f = ecs_filter_init(world, &(ecs_filter_desc_t) {
.terms = {{ Npc }, { InRange }}
});
// New
ecs_filter_t *f = ecs_filter(world, {
.terms = {{ Npc }, { InRange }}
});
  • Performance Improvements. Flecs 3 introduces many performance improvements that speed up almost every part of the ECS, like core data structures, the component storage, indices used to accelerate queries, the table graph, search algorithms and API internals.
  • Usability Improvements. Flecs 3 has fewer concepts, a more streamlined API, less confusing naming and more quality of life improvements than previous releases in both the C and C++ APIs.
  • ECS Documentation. Flecs 3 has a new doc addon that makes it possible to annotate entities, components, systems and more with things like descriptions, user friendly names and hyperlinks. These annotations are stored in regular components which can be read by the ECS API and are read by the Flecs explorer to improve visualization:
Doc annotations visualized in the explorer

What’s next?

Where Flecs 2 was in many ways a transition away from an “old style” archetype ECS to one that support relationships, Flecs 3 has a revamped core that treats relationships as a first class citizen. This made it possible to get rid of a lot of technical debt and legacy code, which opens the door to new features and optimizations.

Here are a few things you can expect in upcoming Flecs releases:

  • Command Merging. One of the most expensive operations in an archetype ECS is moving entities between tables. The command merging feature combines deferred commands for a single entity into a single archetype move, which can drastically reduce the number of times entities are moved between tables.
  • Pluggable Storages. Not all components benefit from being stored in aligned (SoA) arrays in a table. A new storage interface will make it possible to implement new storage types that are stored outside of tables, which can reduce how often an entity is moved between tables, and reduce the total number of components that need to be moved.
  • Dense/Sparse tables. Currently any id, whether it is a tag or component, fragments tables. This can sometimes lead to unnecessary fragmentation which can hurt performance. A new storage feature will introduce “sparse tables”, which are tables that index into “dense tables”, where dense tables only contain components, not tags. This can greatly decrease table fragmentation, while still allowing for entities with many different component/tag combinations.
  • Reachable Cache. This one is a bit more into the weeds. A new memoization data structure is being designed that can cache the results of relationship graph traversal. Graph traversal is a common operation in many parts of Flecs, which the reachable cache will speed up. This will be especially noticeable in apps that are heavy users of relationships or apps with deep hierarchies.
  • Node API. One of the biggest new features on the roadmap is a new node based API that will make it possible to build node graphs from ECS systems. Flecs 3 laid the groundwork for the node API by unifying iterators across the different kinds of queries and systems.

Big Thanks To

Flecs 3 would have been nowhere where it is today without contributions from the community! A special thanks to everyone that contributed PRs and participated in the discussions on Flecs 3 features:

  • @Hexlord
  • @mason-bially
  • @jemc
  • @Metadorius
  • @MewSoul
  • @BlackxSnow
  • @bazhenovc
  • @Sygmei
  • @Jared-Miller
  • @RobertBiehl
  • @photex
  • @BHolman-LBI
  • @Coul33t
  • @tourkit
  • @jtfrson
  • @stickyfingies
  • @ZeroErrors
  • @logankaser
  • @Wesxdz
  • @randy408

Also a big thanks to everyone that sponsored the project ❤️:

  • @LostBoysInteractive
  • @Lexxicon
  • @Zifkan
  • @Nox4041
  • @MatthewOwens
  • @TFlippy
  • @Hexlord
  • @ikrima
  • @silenttowergames
  • @jtferson
  • @wesleysliao
  • @rsms
  • @tcdude
  • @schipdah
  • @Manningham
  • @BlackxSnow
  • @clibequilibrium
  • @ubermenzchen
  • @magmabit
  • @Scaless
  • @photex
  • Everyone that is sponsoring privately!

That’s all folks! If you’d like to try out Flecs, check out the GitHub repository and consider giving it a ⭐️!

If you have any questions, suggestions or projects you’d like to share with others, join the Flecs Discord:

--

--

Sander Mertens

Author of Flecs, an Entity Component System for C and C++