Repository: opencv
Issue: [request / evolution] Provide users with compiled file size break down analysis reports
Labels: feature,category: build/install

# [request / evolution] Provide users with compiled file size break down analysis reports

 * Author: *(vacated)*
 * Link: *(to be determined)*
 * Status: **Draft**
 * Platform: **Mobile first (such as Android and iOS)**, others later
 * Complexity: *(to be determined)*

## Introduction and Rationale

Mobile apps tend to be downloaded over the air. Each app tend to require bundling its own OpenCV binary, i.e. there is no sharing of native binary code between apps. There is need to minimize binary code size, even if that requires modifying the default OpenCV build config.

As a personal anecdote, I was working on an app native backend that uses OpenCV for Android (version 2.4.10 or so). The backend uses only three modules: core, imgproc, and imgcodecs. I used ```objdump``` to casually check the size of the binaries, and found that the majority of binary size was taken up by: IlmImf, followed by ```cv::cvtColor```. Both functionality have small API surface but deep innards. As for ```cvtColor```, much of the binary size was taken up by conversions which are not used; a typical app would only use a few of them. There was no build configuration for excluding certain ```cvtColor``` internal implementations from the binary file.

Having the compiled file size analysis report, with break-downs into certain things such as each image I/O codec, and big-ticket functions such as ```cvtColor```, will help teach OpenCV users how to reduce the binary size if they need to.

## Proposed solution

My simplest solution is to run ```objdump``` on the build output, and then parse that output with Python scripts and emitting a report. 

For Windows (Microsoft Visual C++), there is ```dumpbin```, although that is a lower priority, because it is unrelated to mobile app development. 

The analysis report will process the output of three modules only. Additional modules might be added by amending this proposal.

 * core
 * imgproc
 * imgcodecs

This proposed solution is purely a post-build binary analysis report generation. It does not involve code changes to OpenCV itself. It requires access to the same compiler toolchain used for the build.

With each OpenCV official release, a *sample* analysis report will be accompanied with selected platforms. (The *sample* means "for reference only".) However, because OpenCV users typically need to build from source, they will need to re-run this analysis report on their own build. Therefore, the deliverable of this proposal will need to be shipped as part of the OpenCV build tools.

## Impact on existing code, compatibility

This proposed solution is purely a post-build binary analysis report generation. It does not involve code changes to OpenCV itself. It requires access to the same compiler toolchain used for the build.

## Possible alternatives

Do nothing. Analysis using ```objdump``` can also be done by advanced OpenCV C++ users who work on mobile native code backend. However, many mobile app developers will miss the opportunity to optimize binary size.

## References

 * (Link to ```objdump``` documentation)
 * (Link to an open-source project that parses the output of ```objdump``` and generates binary file size breakdown analysis)
 * (Link to ```dumpbin``` documentation)