Skip to content

Binary size reduction in KernelTypeStrResolver and GraphPartitioner#13172

Merged
edgchen1 merged 7 commits into
mainfrom
edgchen1/binsize
Sep 30, 2022
Merged

Binary size reduction in KernelTypeStrResolver and GraphPartitioner#13172
edgchen1 merged 7 commits into
mainfrom
edgchen1/binsize

Conversation

@edgchen1
Copy link
Copy Markdown
Contributor

Description

Reduce binary size for minimal Android builds.

  • reduce places where Status objects are created in KernelTypeStrResolver::LoadFromOrtFormat()
  • remove some unused parameters (in a base minimal build) and code in graph_partitioner.cc

Motivation and Context

Modest reduction of binary size (-2.8K) in minimal Android build.

bloaty output, comparing 42c0a21 (updated) with 5c89c37 (baseline):

     VM SIZE
 --------------
  +1.8%     +60    D:/source/onnxruntime/onnxruntime/core/framework/graph_partitioner.cc
    [NEW]    +256    onnxruntime::KernelLookup::KernelLookup()
    [NEW]    +244    onnxruntime::KernelRegistryManager::GetKernelRegistriesByProviderType()
    [NEW]     +80    onnxruntime::MakeString<>()
   -38.6%    -520    onnxruntime::PartitionOrtFormatModelImpl()
  +4.0%     +24    [LOAD #1 [RX]]
  -0.2%    -240    [section .rodata]
  -0.2%    -692    [section .text]
    +3.9%    +792    onnxruntime::detail::MakeStringImpl<>()
    [DEL]      -8    __CortexA53843419_103004
    -2.2%     -80    onnxruntime::MakeString<>()
    [DEL]    -244    onnxruntime::KernelRegistryManager::GetKernelRegistriesByProviderType()
    [DEL]    -256    onnxruntime::KernelLookup::KernelLookup()
   -32.7%    -896    std::__ndk1::__hash_table<>::__rehash()
 -21.3% -2.02Ki    D:/source/onnxruntime/onnxruntime/core/framework/kernel_type_str_resolver.cc
    [NEW]    +896    std::__ndk1::__hash_table<>::__rehash()
   -43.9% -1.06Ki    onnxruntime::KernelTypeStrResolver::LoadFromOrtFormat()
   -68.4% -1.83Ki    onnxruntime::detail::MakeStringImpl<>()
  -0.2% -2.84Ki    TOTAL

Note: the graph_partitioner.cc compileunit appears to increase in size, but some items seem to have been moved there from [section .text].

Comment thread onnxruntime/core/framework/graph_partitioner.cc Outdated
@cloudhan
Copy link
Copy Markdown
Contributor

Off topic, when working on #11071, I notice that using ostringstream introduce many locale related object, and contribute a huge portion of binary size. If you are able to remove std::basic_ostream usage in min built, it might improve binary size by ~80kb

Copy link
Copy Markdown
Contributor

@skottmckay skottmckay left a comment

Choose a reason for hiding this comment

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

:shipit:

@edgchen1 edgchen1 merged commit aae35f2 into main Sep 30, 2022
@edgchen1 edgchen1 deleted the edgchen1/binsize branch September 30, 2022 20:50
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.

3 participants