You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And we noticed a notable size increment:
Download size: +1.08MB
Install size: +2.51MB
We have a large codebase and the app size is a big concern for us, so I tried to find ways to reduce the impact.
I noticed that there is a macro tflite_ios_xcframework which creates the xcframework and then modfies the object files to hide public symbols.
So I created a new target using the rule apple_static_xcframework directly. See omarzl/tensorflow@945d7ec (I can send the pull request if it helps)
I named this target TensorFlowLiteC_static_xcframework, then I compiled it:
There was a minor improvement using it:
Download size: +0.49MB
Install size: +1.23MB
Finally I tried using the original tflite_ios_xcframework target TensorFlowLiteC_xcframework but with -Os optimization, I was expecting a minor reduction but I was wrong, instead it incremented:
Download size: +1.30MB
Install size: +3.03MB
I understand the reasons behind hiding symbols since they can cause a symbol collision ending in unexpected behaviors or crashes in the app but these tests found out that it can cause an increment in app size.
For our case, we don't have any symbol collision with Tensorflow so we can use an un-hided version of the xcframework which benefit us in less app size impact. As a side note: The linker ld warns you if there is a symbol collision, we opt to make warnings to errors to catch any issue of this kind by adding the flag -Wl,-fatal_warnings
In summary, I don't think there is much that can be done without hiding the symbols, I open this issue in case anyone finds a better solution to reduce the size impact and to document what I have found.
Standalone code to reproduce the issue
The compilation commands were written above.
Relevant log output
No response
The text was updated successfully, but these errors were encountered:
Original Issue: tensorflow/tensorflow#62671
Original Author: @omarzl
Issue type
Performance
Have you reproduced the bug with TensorFlow Nightly?
No
Source
source
TensorFlow version
2.15.0
Custom code
Yes
OS platform and distribution
No response
Mobile device
No response
Python version
No response
Bazel version
6.1.0
GCC/compiler version
No response
CUDA/cuDNN version
No response
GPU model and memory
No response
Current behavior?
I open this issue to share my findings regarding app size impact of
TensorFlowLiteC
binary in iOSCurrently we are migrating from a really old version to
v2.15.0
:https://github.com/tensorflow/tensorflow/blob/v2.15.0/tensorflow/lite/ios/TensorFlowLiteC.podspec
And we noticed a notable size increment:
Download size:
+1.08MB
Install size:
+2.51MB
We have a large codebase and the app size is a big concern for us, so I tried to find ways to reduce the impact.
I noticed that there is a macro
tflite_ios_xcframework
which creates thexcframework
and then modfies the object files to hide public symbols.So I created a new target using the rule
apple_static_xcframework
directly.See omarzl/tensorflow@945d7ec (I can send the pull request if it helps)
I named this target
TensorFlowLiteC_static_xcframework
, then I compiled it:By using the xcframework without hidden symbols I noticed that the size increment was notable less
-50%
:Download size:
+0.50MB
Install size:
+1.24MB
Then I changed the clang optimization to
-Os
instead of-O3
which is the default one used by Bazel inopt
config:There was a minor improvement using it:
Download size:
+0.49MB
Install size:
+1.23MB
Finally I tried using the original
tflite_ios_xcframework
targetTensorFlowLiteC_xcframework
but with-Os
optimization, I was expecting a minor reduction but I was wrong, instead it incremented:Download size:
+1.30MB
Install size:
+3.03MB
Here is a summary of my tests:
TensorFlowLiteC_xcframework
TensorFlowLiteC_static_xcframework
TensorFlowLiteC_xcframework
&-Os
optTensorFlowLiteC_static_xcframework
&-Os
opt+1.08MB
+0.50MB
+0.49MB
+1.30MB
+2.51MB
+1.24MB
+1.23MB
+3.03MB
I understand the reasons behind hiding symbols since they can cause a symbol collision ending in unexpected behaviors or crashes in the app but these tests found out that it can cause an increment in app size.
For our case, we don't have any symbol collision with Tensorflow so we can use an un-hided version of the xcframework which benefit us in less app size impact.
As a side note: The linker
ld
warns you if there is a symbol collision, we opt to make warnings to errors to catch any issue of this kind by adding the flag-Wl,-fatal_warnings
Finally looking at the code in
hide_xcframework_symbols_with_allowlist.sh
https://github.com/tensorflow/tensorflow/blob/6887368d6d46223f460358323c4b76d61d1558a8/tensorflow/lite/ios/hide_xcframework_symbols_with_allowlist.sh#L120
I understand that by using
xcrun ld -r
you are changing public symbols to private ones to prevent this symbol collision but I don't see you are generating a dynamic executable, I see that the output is still a Mach-O object (MH_OBJECT
) so I think that this documentation https://www.tensorflow.org/lite/guide/build_ios is wrong since there isn't a dynamic framework, it is still a static framework but with hidden symbols.In summary, I don't think there is much that can be done without hiding the symbols, I open this issue in case anyone finds a better solution to reduce the size impact and to document what I have found.
Standalone code to reproduce the issue
Relevant log output
No response
The text was updated successfully, but these errors were encountered: