Skip to content

Performance

Alan Jefferson edited this page Jan 27, 2020 · 2 revisions

EnTT is mostly templates, and templates come at a cost to compile time. The following is various considerations to make when working with EnTT with regards to keeping compile time in check.

Table of contents


Strive towards 0 templates

An unreachable goal, as EnTT is almost entirely made up of templates. But something to strive for. If you are in a position to either call a template or not, don't.


Each template instantiation costs 200 ms

Tune your mind to this number. It may not seem like a single template could cause such strain, but internally, an EnTT template calls on other templates, which in turn calls on other templates. A translation unit with 40 calls can expand into 2,000+ template instantiation, adding 10 seconds or more to your compile time.


Prefer for to each

A call to each implies several additional template instantiations, as each is a template which calls on other templates. If you can, prefer doing this

// Yes
for (auto entity : registry.view<A>()) {
  // Do something with `entity`
}

// No
registry.view<A>().each([](auto entity, const auto&) {
  // Do something with `entity`
});

Prefer Single-Component Views

Whenever you ask for more than one component in a view, a separate template expansion party ensues.

Clone this wiki locally