Skip to content

feat(tv-casting-app): Phase 2 APK size reduction (2.8 MB → 2.6 MB)#71482

Open
chrisdecenzo wants to merge 3 commits intoproject-chip:masterfrom
chrisdecenzo:casting-apk-size-reduction-phase2
Open

feat(tv-casting-app): Phase 2 APK size reduction (2.8 MB → 2.6 MB)#71482
chrisdecenzo wants to merge 3 commits intoproject-chip:masterfrom
chrisdecenzo:casting-apk-size-reduction-phase2

Conversation

@chrisdecenzo
Copy link
Copy Markdown
Contributor

Summary

Remove 10 non-essential infrastructure clusters from the slim casting-cluster-objects.cpp and disable their server-side definitions in tv-casting-app.zap and tv-casting-app.matter. Disable extra data-model logging, host unit-test hooks, and RTTI for size-optimized builds. Make ICD client dependencies conditional on optimize_apk_size.

Cluster changes:

  • Remove .ipp includes for 10 clusters: EthernetNetworkDiagnostics, SoftwareDiagnostics, WiFiNetworkDiagnostics, TimeSynchronization, TimeFormatLocalization, UnitLocalization, FixedLabel, UserLabel, IcdManagement, LocalizationConfiguration
  • Retain Groupcast (required by InteractionModelEngine.cpp)
  • Remove orphaned CommandIsFabricScoped entries for TimeSynchronization and IcdManagement
  • Disable server-side ZAP/matter definitions for removed clusters

Build flag changes (optimize_apk_size=true only):

  • chip_data_model_extra_logging=false via android.py
  • enable_rtti=false via android.py and args.gni
  • CONFIG_BUILD_FOR_HOST_UNIT_TEST=0 via BUILD.gn defines
  • ICD client deps excluded via BUILD.gn conditional
  • Add src/controller as direct dep (was transitive via ICD)

Measured results (arm64-v8a):

  • Android: libTvCastingApp.so 2.8 MB -> 2.6 MB (-7%)
  • Darwin: __TEXT 2.8 MB -> 2.7 MB (cluster trimming only)

Testing

iOS and Android regression

Remove 10 non-essential infrastructure clusters from the slim
casting-cluster-objects.cpp and disable their server-side definitions
in tv-casting-app.zap and tv-casting-app.matter. Disable extra
data-model logging, host unit-test hooks, and RTTI for size-optimized
builds. Make ICD client dependencies conditional on optimize_apk_size.

Cluster changes:
- Remove .ipp includes for 10 clusters: EthernetNetworkDiagnostics,
  SoftwareDiagnostics, WiFiNetworkDiagnostics, TimeSynchronization,
  TimeFormatLocalization, UnitLocalization, FixedLabel, UserLabel,
  IcdManagement, LocalizationConfiguration
- Retain Groupcast (required by InteractionModelEngine.cpp)
- Remove orphaned CommandIsFabricScoped entries for TimeSynchronization
  and IcdManagement
- Disable server-side ZAP/matter definitions for removed clusters

Build flag changes (optimize_apk_size=true only):
- chip_data_model_extra_logging=false via android.py
- enable_rtti=false via android.py and args.gni
- CONFIG_BUILD_FOR_HOST_UNIT_TEST=0 via BUILD.gn defines
- ICD client deps excluded via BUILD.gn conditional
- Add src/controller as direct dep (was transitive via ICD)

Measured results (arm64-v8a):
- Android: libTvCastingApp.so 2.8 MB -> 2.6 MB (-7%)
- Darwin: __TEXT 2.8 MB -> 2.7 MB (cluster trimming only)
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements Phase 2 size optimizations for the TV casting app, including the removal of ten non-essential infrastructure clusters, disabling RTTI and extra data-model logging for Android, and excluding ICD client dependencies and host unit-test hooks. The documentation in the size analysis files incorrectly lists 11 removed clusters; feedback suggests correcting this count to 10 to align with the actual code changes.

Comment on lines +349 to +364
The following 11 infrastructure clusters were removed from the slim cluster file
and disabled in the ZAP server-side configuration. A casting client does not
serve these clusters — they are diagnostic, localization, and management clusters
irrelevant to the casting use case:

- EthernetNetworkDiagnostics
- SoftwareDiagnostics
- WiFiNetworkDiagnostics
- TimeSynchronization
- TimeFormatLocalization
- UnitLocalization
- FixedLabel
- UserLabel
- Groupcast
- IcdManagement
- LocalizationConfiguration
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This section incorrectly states that 11 clusters were removed, including Groupcast. According to the PR description and code changes, Groupcast is intentionally retained, and only 10 clusters are removed. Please update this documentation to be consistent. The count on line 377 should also be corrected from 11 to 10.

References
  1. When documenting technical terms or component names, ensure consistency in capitalization and spelling throughout the document, especially when referring to names defined in source code.


| Optimization | Darwin applicability | Notes |
|---|---|---|
| Cluster trimming (11 clusters) | ✅ Applies | The slim `casting-cluster-objects.cpp` is shared between Android and Darwin. Removing 11 non-essential infrastructure clusters reduces code in `libTvCastingCommon.a` identically. |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This should be 'Cluster trimming (10 clusters)' and the notes should refer to 10 removed clusters, not 11, to be consistent with the code changes.

References
  1. When documenting technical terms or component names, ensure consistency in capitalization and spelling throughout the document, especially when referring to names defined in source code.

…ssors

Add explicit build scoping for the TV Casting App size-optimized build:

- chip_cluster_server_source_override: compile only 13 cluster server
  dirs (12 commissioning + content-app-observer) instead of all ~44
  discovered from the .matter file
- chip_accessors_source_override: compile only 29 casting-relevant
  cluster accessors instead of the full ~200+ cluster Accessors.cpp
- casting-cluster-servers.gni: override list for cluster servers
- casting-Accessors.cpp: slim accessors for 29 clusters

Both overrides follow the same pattern as the existing
chip_cluster_objects_source_override from phase 2. All changes are
gated behind optimize_apk_size=true; default builds are unaffected.

Measured result: libTvCastingApp.so remains at 2.6 MB (arm64-v8a)
because LTO and --gc-sections were already stripping the excluded
code. The overrides reduce compile time and intermediate .o sizes,
and prevent regressions if linker behavior changes upstream.

Also documents jsoncpp/jsontlv removal as not feasible (JNI
interaction model layer uses it at runtime) and controller library
split as future work (~1.3 MB potential, requires BUILD.gn refactor).
@github-actions
Copy link
Copy Markdown

PR #71482: Size comparison from f82be95 to 1b78a4e

Full report (5 builds for cc32xx, realtek, stm32)
platform target config section f82be95 1b78a4e change % change
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 559874 559874 0 0.0
RAM 204568 204568 0 0.0
lock CC3235SF_LAUNCHXL FLASH 592742 592742 0 0.0
RAM 204816 204816 0 0.0
realtek light-switch-app rtl8777g FLASH 680808 680824 16 0.0
RAM 101600 101600 0 0.0
lighting-app rtl8777g FLASH 724752 724768 16 0.0
RAM 101956 101956 0 0.0
stm32 light STM32WB5MM-DK FLASH 475452 475468 16 0.0
RAM 141388 141388 0 0.0

@chrisdecenzo chrisdecenzo requested a review from a team as a code owner April 10, 2026 18:33
@github-actions
Copy link
Copy Markdown

PR #71482: Size comparison from f82be95 to 53a0e72

Full report (5 builds for cc32xx, realtek, stm32)
platform target config section f82be95 53a0e72 change % change
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 559874 559874 0 0.0
RAM 204568 204568 0 0.0
lock CC3235SF_LAUNCHXL FLASH 592742 592742 0 0.0
RAM 204816 204816 0 0.0
realtek light-switch-app rtl8777g FLASH 680808 680824 16 0.0
RAM 101600 101600 0 0.0
lighting-app rtl8777g FLASH 724752 724768 16 0.0
RAM 101956 101956 0 0.0
stm32 light STM32WB5MM-DK FLASH 475452 475468 16 0.0
RAM 141388 141388 0 0.0

…el_overrides_dir

Replace chip_cluster_objects_source_override,
chip_cluster_server_source_override, chip_accessors_source_override,
chip_tlv_decoder_attribute_source_override,
chip_tlv_decoder_event_source_override, and matter_enable_tlv_decoder_cpp
with a single chip_data_model_overrides_dir directory-based argument.

When set to a non-empty path, the build system looks for well-known
filenames (casting-cluster-objects.cpp, casting-Accessors.cpp,
casting-cluster-servers.gni, casting-CHIPAttributeTLVValueDecoder.cpp,
casting-CHIPEventTLVValueDecoder.cpp) inside the directory and uses
them as source overrides. When empty (default), all consumers fall
back to the full zap-generated sources.

Also adds generate_slim_overrides.py and casting-cluster-config.yaml
for regenerating slim override files from full zap-generated sources.

Updates android.py, both args.gni files, all GN consumers, docs, and
property tests. 76/76 tests pass.
@chrisdecenzo chrisdecenzo force-pushed the casting-apk-size-reduction-phase2 branch from 53a0e72 to 8c748c3 Compare April 10, 2026 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant