- Home
- Skills
- Openharmonyinsight
- Openharmony Skills
- Header Optimization
header-optimization_skill
- Python
0
GitHub Stars
2
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill openharmonyinsight/openharmony-skills --skill header-optimization- README.md6.3 KB
- SKILL.md35.4 KB
Overview
This skill optimizes C++ header file compilation efficiency by systematically reducing header dependencies and moving non-trivial implementations out of headers. It focuses on safely replacing heavy includes with forward declarations, removing unused includes, and relocating method bodies to corresponding .cpp files while preserving business logic.
How this skill works
Analyze the target header or extract the header referenced by test_header.cpp, detect inline method implementations longer than three lines, and move them to a .cpp file (creating one if needed). Inspect each #include to determine actual usage, remove unused includes, and convert applicable includes to forward declarations. Optionally split out constants/enums into a small header when it measurably reduces coupling.
When to use it
- Optimize a specific .h file to reduce compilation time or memory
- Analyze header usage that test_header.cpp references (read-only)
- Reduce unnecessary transitive includes and heavy dependencies
- Move multi-line inline implementations to .cpp to shrink headers
- Prepare headers for large-scale refactoring or continuous integration
Best practices
- Preserve all runtime and API behavior; only change structure, not logic
- Keep trivial one-line getters/setters inline for performance
- Prefer forward declarations for pointer/ref/smart-pointer usages
- Add precise includes for types that are used by value, inheritance, templates, or static members
- Limit file creation—create new headers only for splitting constants/enums with clear benefit
- Verify each header and its new .cpp compile standalone after changes
Example use cases
- Replace a heavy recognizer include with a forward declaration and precise includes for GestureEventFunc
- Move 10+ line inline methods from click_event.h into click_event.cpp to shrink header size
- Remove an unused include that was only providing an indirect type and document the change
- Split a header to extract a frequently-used enum into a small types header to reduce coupling
- Run analysis-only mode to generate a list of recommended include removals and forward declarations
FAQ
No. Changes are structural only—implementations are moved but logic and public APIs remain identical.
When must I keep a full #include instead of using a forward declaration?
Keep full includes when you inherit from a type, have a member of the concrete type, instantiate templates, access static members, or call inline methods that need a complete definition.
Can smart pointers (RefPtr/unique_ptr/shared_ptr) use forward declarations?
Yes. Member variables or parameters using smart pointers generally work with forward declarations; actual instantiation or use of methods requires the full include in the .cpp.