Skip to content

Reduce moc Parse Time by Forward-Declaring Vehicle in Headers #14167

@DonLakeFlyer

Description

@DonLakeFlyer

Reduce moc Parse Time by Forward-Declaring Vehicle in Headers

Background

Vehicle.h is 1454 lines and is included by 9 headers that each trigger a moc run.
Since moc must parse the entire translation unit including all transitive includes, each
of these headers pays the full cost of parsing Vehicle.h even when only pointer-level
access is needed. Replacing the full include with a forward declaration in eligible
headers will meaningfully reduce moc parse time.

Immediate Wins — Headers That Can Forward-Declare Vehicle Today

These headers only use Vehicle at the pointer level and have no nested type access.
The full #include "Vehicle.h" can be replaced with class Vehicle; and the include
moved to the corresponding .cpp file.

Header Usage
src/Camera/QGCCameraManager.h Vehicle*, QPointer<Vehicle> — no nested type access
src/QmlControls/FactValueGrid.h Vehicle* in members, signals, parameters — no nested type access

Blocked — Requires Vehicle Refactoring First

The following headers access nested enum or constant types defined inside Vehicle,
which prevent forward declaration. The full type definition is required to resolve these.

Header Blocking Usage
src/Utilities/StateMachine/States/RequestMessageState.h Vehicle::RequestMessageResultHandlerFailureCode_t
src/Utilities/StateMachine/States/RetryableRequestMessageState.h Vehicle::RequestMessageResultHandlerFailureCode_t
src/Vehicle/Actuators/ActuatorActions.h Vehicle::MavCmdResultFailureCode_t
src/Vehicle/Actuators/ActuatorTesting.h Vehicle::MavCmdResultFailureCode_t
src/Vehicle/Actuators/MotorAssignment.h Vehicle::MavCmdResultFailureCode_t
src/Vehicle/Autotune.h Vehicle::MavCmdResultFailureCode_t
src/FirmwarePlugin/FirmwarePlugin.h Vehicle::versionNotSetValue

Recommended Fix for Blocked Headers

Extract the following from the Vehicle class into a new lightweight VehicleTypes.h header:

  • MavCmdResultFailureCode_t
  • RequestMessageResultHandlerFailureCode_t
  • versionNotSetValue

All 7 blocked headers can then include only VehicleTypes.h and forward-declare
Vehicle, avoiding the full 1454-line parse for each of their moc runs.

Steps

  1. Create src/Vehicle/VehicleTypes.h containing the extracted enums/constants
  2. Update Vehicle.h to include VehicleTypes.h (preserving existing behaviour)
  3. Replace #include "Vehicle.h" with class Vehicle; in QGCCameraManager.h and FactValueGrid.h
  4. Replace #include "Vehicle.h" with #include "VehicleTypes.h" + class Vehicle; in the 7 blocked headers
  5. Add #include "Vehicle.h" to the corresponding .cpp files where the full type is needed

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions