Skip to content

Reduce moc parse time by 60% with lightweight MAVLink headers#14241

Merged
DonLakeFlyer merged 1 commit intomavlink:masterfrom
DonLakeFlyer:reduce-moc-parse-time
Mar 30, 2026
Merged

Reduce moc parse time by 60% with lightweight MAVLink headers#14241
DonLakeFlyer merged 1 commit intomavlink:masterfrom
DonLakeFlyer:reduce-moc-parse-time

Conversation

@DonLakeFlyer
Copy link
Copy Markdown
Collaborator

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

Metric Before After Change
Total moc time 457.9s 184.5s -273s (60%)
Slow headers (>100ms) 182 71 -111
Fast headers (<20ms) 367 452 +85

Timing methodology: single-pass moc --output-dep-file /dev/null across all 550 .h files in src/ and test/, using include paths from compile_commands.json.

Approach

The root cause was MAVLinkLib.h pulling 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 the mavlink_message_t base type — not the full message pack/unpack machinery.

New lightweight headers

Header Contents Preprocessed lines
MAVLinkEnums.h (build-generated) All 253 MAVLink enum typedefs ~5,500
MAVLinkMessageType.h mavlink_message_t, mavlink_channel_t, base types ~2,700
QGCMAVLinkTypes.h FirmwareClass_t, VehicleClass_t, maxRcChannels ~50
VehicleTypes.h MavCmdResultFailureCode_t, RequestMessageResultHandlerFailureCode_t ~30

Header migration

  • 25 headers switched from MAVLinkLib.h or QGCMAVLink.h to MAVLinkEnums.h and/or MAVLinkMessageType.h
  • 6 headers switched from QGCMAVLink.h to QGCMAVLinkTypes.h
  • 8 headers switched from Vehicle.h to VehicleTypes.h + forward declaration
  • QGCMAVLink.h itself switched from MAVLinkLib.h to MAVLinkEnums.h + MAVLinkMessageType.h (biggest single impact — 18 direct + 61 transitive includers)

Build-generated MAVLinkEnums.h

cmake/GenerateMAVLinkEnums.py extracts enum typedef sections from all 19 MAVLink dialect headers (text between // ENUM DEFINITIONS and // MESSAGE DEFINITIONS markers). The CMake custom command runs after the MAVLink CPM package is fetched and only regenerates when content changes.

Backward compatibility

Vehicle inherits from VehicleTypes and QGCMAVLink inherits from QGCMAVLinkTypes, so all existing code using Vehicle::MavCmdResultFailureCode_t or QGCMAVLink::VehicleClass_t etc. continues to work unchanged. The PCH still includes MAVLinkLib.h for .cc file compilation.

Remaining slow headers

The remaining 71 slow headers all trace back to 16 Tier 3 headers that still need MAVLinkLib.h because 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.

This comment was marked as resolved.

This comment was marked as resolved.

@DonLakeFlyer DonLakeFlyer force-pushed the reduce-moc-parse-time branch 2 times, most recently from 1c61ef6 to c10ddd1 Compare March 30, 2026 00:34
@github-actions github-actions bot added the github_actions Pull requests that update GitHub Actions code label Mar 30, 2026
@DonLakeFlyer DonLakeFlyer requested a review from Copilot March 30, 2026 00:34

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 79 out of 79 changed files in this pull request and generated no new comments.

…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%).
@DonLakeFlyer DonLakeFlyer force-pushed the reduce-moc-parse-time branch from 8bb896e to 3b2ffec Compare March 30, 2026 01:41
@github-actions
Copy link
Copy Markdown
Contributor

Build Results

Platform Status

Platform Status Details
Linux Passed View
Windows Passed View
MacOS Passed View
Android Passed View

All builds passed.

Pre-commit

Check Status Details
pre-commit Failed (non-blocking) View

Pre-commit hooks: 4 passed, 32 failed, 7 skipped.

Test Results

linux-sanitizers: 67 passed, 0 skipped
linux_gcc_64: 67 passed, 0 skipped
Total: 134 passed, 0 skipped

Artifact Sizes

Artifact Size
QGroundControl 248.06 MB
QGroundControl 338.19 MB
QGroundControl-aarch64 177.30 MB
QGroundControl-installer-AMD64 134.97 MB
QGroundControl-installer-AMD64-ARM64 77.61 MB
QGroundControl-installer-ARM64 106.32 MB
QGroundControl-mac 188.67 MB
QGroundControl-windows 188.70 MB
QGroundControl-x86_64 172.43 MB
No baseline available for comparison---
Updated: 2026-03-30 02:40:20 UTC • Triggered by: Android

@DonLakeFlyer DonLakeFlyer merged commit 5bf01cc into mavlink:master Mar 30, 2026
24 of 25 checks passed
@DonLakeFlyer DonLakeFlyer deleted the reduce-moc-parse-time branch March 30, 2026 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CMake github_actions Pull requests that update GitHub Actions code MAVLink size/M Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants