# Simpleperf case study: Fast initialization of TFLite's Memory Arena

DevFeed: [Simpleperf case study: Fast initialization of TFLite's Memory Arena](<https://devfeed.tech/articles/simpleperf-case-study-fast-initialization-of-tflite-s-memory-arena-7382.md>)

Original publisher: [Read original article](<https://blog.tensorflow.org/2023/08/simpleperf-case-study-fast.html>)

Author: TensorFlow Blog (noreply@blogger.com)

Published: 2023-08-09T16:00:00Z

Content type: tutorial

Language: en

Sources: [The TensorFlow Blog](<https://devfeed.tech/sources/the-tensorflow-blog.md>)

Topics: [TensorFlow Lite](<https://devfeed.tech/topics/tensorflow-lite.md>), [Optimization](<https://devfeed.tech/topics/optimization.md>), [Machine learning](<https://devfeed.tech/topics/machine-learning.md>), [Android](<https://devfeed.tech/topics/android.md>), [Development](<https://devfeed.tech/topics/development.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [adb](<https://devfeed.tech/tags/adb.md>), [cache](<https://devfeed.tech/tags/cache.md>), [display](<https://devfeed.tech/tags/display.md>), [models](<https://devfeed.tech/tags/models.md>), [performance](<https://devfeed.tech/tags/performance.md>), [performance-optimization](<https://devfeed.tech/tags/performance-optimization.md>), [profiling](<https://devfeed.tech/tags/profiling.md>), [reduce](<https://devfeed.tech/tags/reduce.md>), [tensorflow-lite](<https://devfeed.tech/tags/tensorflow-lite.md>), [visualization](<https://devfeed.tech/tags/visualization.md>)

## AI overview

This developer article presents a case study on optimizing TensorFlow Lite memory arena initialization. It explains how to profile an on-device machine-learning pipeline with Simpleperf, generate profile data, visualize it with pprof, and identify runtime bottlenecks such as ArenaPlanner::ExecuteAllocations.

## Source excerpt

Posted by Alan Kelly, Software Engineer One of our previous articles, Optimizing TensorFlow Lite Runtime Memory, discusses how TFLite's memory arena minimizes memory usage by sharing buffers between tensors. This means we can run models on even smaller edge devices. In today's article, I will describe the performance optimization of the memory arena initialization so that our users get the benefit of low memory usage with little additional overhead. ML is normally deployed on-device as part of a larger pipeline. TFLite is used because it's fast and lightweight, but the rest of the pipeline must also be fast. Profiling on the target device with representative data lets us identify the slowest parts of the pipeline so that we can optimize the most important part of the code. In this article, I will describe the profiling and optimization of TFLite's memory arena with instructions on how to use Simpleperf and visualize the results. Sample commands are given. It is assumed that the Android NDK is installed and that you have a development device that you can connect to using adb. Simpleperf Simpleperf comes with some scripts to make it easier to use. run_simpleperf_on_device.py pushes simpleperf to the device and runs your binary with the given arguments. /usr/lib/android-ndk/simpleperf/run_simpleperf_on_device.py record -call-graph fp /data/local/tmp/my_binary arg0 arg1 ... This will generate the output file perf.data which you must then copy back to your computer. adb pull /data/local/tmp/perf.data You then generate the binary cache which contains all the information needed later to generate a useful profile. /usr/lib/android-ndk/simpleperf/binary_cache_builder.py -lib /your/binarys/folder -i perf.data And generate the proto buffer used for visualization: /usr/lib/android-ndk/simpleperf/pprof_proto_generator.py --ndk_path=/path/to/android-ndk -i perf.data -o profile.proto You can then display the results this using pprof: pprof -http :8888 profile.proto And open localhos