Skip to content

Fix various iOS treemap inaccuracies #473

Merged
trevor-e merged 13 commits intomainfrom
telkins/counting
Nov 14, 2025
Merged

Fix various iOS treemap inaccuracies #473
trevor-e merged 13 commits intomainfrom
telkins/counting

Conversation

@trevor-e
Copy link
Member

@trevor-e trevor-e commented Nov 14, 2025

There were a couple bugs that I was finally able to track down.

  1. Not handling zerofill sections properly. These sections contain uninitialized symbols and don't take up disk space. The section has a size but that's only used when loading into virtual memory. If you summed up all the section sizes in lief they were greater than the segment size due to this bug.
  2. Handling Swift symbols we can't attribute. Our custom demangling code seems to have a bug and can't demangle about ~1% of symbols, and we were silently dropping these during our calculation.
  3. Moves unmapped nodes to be per segment.

There are some slight counting discrepancies but very small now, only 7368 over-counting bytes for the main Hackernews binary:

           WARNING  macho.treemap.size_mismatch | binary_name=HackerNews file_size=3153920 treemap_size=3161288 difference=7368 difference_type=over_counted  
                    percentage=0.23                                                                                                                           
           DEBUG    Building treemap for Common                                                                                                               
           WARNING  macho.treemap.size_mismatch | binary_name=Common file_size=192512 treemap_size=194536 difference=2024 difference_type=over_counted        
                    percentage=1.05                                                                                                                           
           DEBUG    Building treemap for Reaper                                                                                                               
           WARNING  macho.treemap.size_mismatch | binary_name=Reaper file_size=53248 treemap_size=35792 difference=17456 difference_type=missing              
                    percentage=32.78                                                                                                                          
           DEBUG    Building treemap for Sentry                                                                                                               
           WARNING  macho.treemap.size_mismatch | binary_name=Sentry file_size=53248 treemap_size=35792 difference=17456 difference_type=missing              
                    percentage=32.78                                                                                                                          
           DEBUG    Building treemap for HackerNewsHomeWidgetExtension                                                                                        
           WARNING  macho.treemap.size_mismatch | binary_name=HackerNewsHomeWidgetExtension file_size=155648 treemap_size=157672 difference=2024              
                    difference_type=over_counted percentage=1.3 

@codecov
Copy link

codecov bot commented Nov 14, 2025

Codecov Report

❌ Patch coverage is 82.64463% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.38%. Comparing base (47b5c92) to head (d3d57a9).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...rc/launchpad/size/treemap/macho_element_builder.py 85.33% 4 Missing and 7 partials ⚠️
tests/integration/size/test_treemap_generation.py 81.57% 7 Missing ⚠️
src/launchpad/size/analyzers/apple.py 40.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #473      +/-   ##
==========================================
+ Coverage   80.35%   80.38%   +0.03%     
==========================================
  Files         159      159              
  Lines       13465    13508      +43     
  Branches     1424     1437      +13     
==========================================
+ Hits        10820    10859      +39     
- Misses       2109     2110       +1     
- Partials      536      539       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@trevor-e trevor-e marked this pull request as ready for review November 14, 2025 16:53
section_name = self._parse_lief_name(section.name)
section_infos.append(SectionInfo(name=section_name, size=section.size))
is_zerofill = section.type == lief.MachO.Section.TYPE.ZEROFILL
section_infos.append(SectionInfo(name=section_name, size=section.size, is_zerofill=is_zerofill))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just not append to section_infos at all if it's zero fill? That seems easier?

Copy link
Member Author

Choose a reason for hiding this comment

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

spoke offline, basically want to keep this data unfiltered and have downstream consumers handle filtering stuff out

@trevor-e trevor-e merged commit 416af31 into main Nov 14, 2025
21 checks passed
@trevor-e trevor-e deleted the telkins/counting branch November 14, 2025 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants