celeritas-project / celeritas

Celeritas is a new Monte Carlo transport code designed to accelerate scientific discovery in high energy physics by improving detector simulation throughput and energy efficiency using GPUs.
https://celeritas-project.github.io/celeritas/
Other
64 stars 35 forks source link

Reexamine use of virtual inheritance #1404

Open sethrj opened 2 months ago

sethrj commented 2 months ago

Virtual+multiple inheritance certainly works as a design pattern but it has some pretty large overhead both in code and object size. Even empty classes (default destructors, no data) require extra construction vtables. Adding mutable/base interfaces for the action classes increases action class setup/teardown/vtable/typeinfo code size about 30% in the simplest case, most of it in initialization. Eliminating virtual inheritance reduces the code size by another 40% after that.

We need to at least make sure that we only use virtual inheritance with hierarchies as shallow as possible, for as few as possible classes, and only using those at a high level.