Reduce moc parse time by 60% with lightweight MAVLink headers#14241
Merged
DonLakeFlyer merged 1 commit intomavlink:masterfrom Mar 30, 2026
Merged
Reduce moc parse time by 60% with lightweight MAVLink headers#14241DonLakeFlyer merged 1 commit intomavlink:masterfrom
DonLakeFlyer merged 1 commit intomavlink:masterfrom
Conversation
b222686 to
f03ad9f
Compare
1c61ef6 to
c10ddd1
Compare
c10ddd1 to
8bb896e
Compare
…eight headers Replace MAVLinkLib.h (~180,000 preprocessed lines) with targeted lightweight headers in files that only need enums or base types: - MAVLinkEnums.h (build-generated): enum typedefs only (~5,200 lines) - MAVLinkMessageType.h: mavlink_message_t and base types (~2,700 lines) - QGCMAVLinkTypes.h: FirmwareClass_t, VehicleClass_t, maxRcChannels - VehicleTypes.h: MavCmdResultFailureCode_t, RequestMessageResultHandlerFailureCode_t Also replace Vehicle.h includes with forward declarations and VehicleTypes.h where only Vehicle enum types are needed in headers. Measured moc parse time across all 550 headers: Before: 458s total, 182 slow (>100ms), 367 fast (<20ms) After: 185s total, 71 slow (>100ms), 452 fast (<20ms) Total moc parse time reduced by 273 seconds (60%).
8bb896e to
3b2ffec
Compare
Contributor
Build ResultsPlatform Status
All builds passed. Pre-commit
Pre-commit hooks: 4 passed, 32 failed, 7 skipped. Test Resultslinux-sanitizers: 67 passed, 0 skipped Artifact Sizes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace heavy
MAVLinkLib.h(~180,000 preprocessed lines) with targeted lightweight headers in files that only need enums or base types. This reduces total moc parse time across all 550 headers by 273 seconds (60%).Measured Results
Timing methodology: single-pass
moc --output-dep-file /dev/nullacross all 550.hfiles insrc/andtest/, using include paths fromcompile_commands.json.Approach
The root cause was
MAVLinkLib.hpulling in all 387 MAVLink message headers (~180k preprocessed lines) through every header that needed even a single MAVLink enum. Most headers only need enums (MAV_CMD,MAV_TYPE, etc.) or themavlink_message_tbase type — not the full message pack/unpack machinery.New lightweight headers
MAVLinkEnums.h(build-generated)MAVLinkMessageType.hmavlink_message_t,mavlink_channel_t, base typesQGCMAVLinkTypes.hFirmwareClass_t,VehicleClass_t,maxRcChannelsVehicleTypes.hMavCmdResultFailureCode_t,RequestMessageResultHandlerFailureCode_tHeader migration
MAVLinkLib.horQGCMAVLink.htoMAVLinkEnums.hand/orMAVLinkMessageType.hQGCMAVLink.htoQGCMAVLinkTypes.hVehicle.htoVehicleTypes.h+ forward declarationQGCMAVLink.hitself switched fromMAVLinkLib.htoMAVLinkEnums.h+MAVLinkMessageType.h(biggest single impact — 18 direct + 61 transitive includers)Build-generated
MAVLinkEnums.hcmake/GenerateMAVLinkEnums.pyextracts enum typedef sections from all 19 MAVLink dialect headers (text between// ENUM DEFINITIONSand// MESSAGE DEFINITIONSmarkers). The CMake custom command runs after the MAVLink CPM package is fetched and only regenerates when content changes.Backward compatibility
Vehicleinherits fromVehicleTypesandQGCMAVLinkinherits fromQGCMAVLinkTypes, so all existing code usingVehicle::MavCmdResultFailureCode_torQGCMAVLink::VehicleClass_tetc. continues to work unchanged. The PCH still includesMAVLinkLib.hfor.ccfile compilation.Remaining slow headers
The remaining 71 slow headers all trace back to 16 Tier 3 headers that still need
MAVLinkLib.hbecause they use specific message struct types (mavlink_command_long_t,mavlink_file_transfer_protocol_t, etc.) in their declarations. These could be addressed in a follow-up.