Coder Social home page Coder Social logo

avatarchik / unity3d.uselessattributestripper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from saladlab/unity3d.uselessattributestripper

0.0 1.0 0.0 1.22 MB

Useless attribute stripper for IL2CPPed executable. It will help for reducing app size for iOS.

License: MIT License

Batchfile 3.15% F# 6.81% Python 17.46% C# 72.57%

unity3d.uselessattributestripper's Introduction

Unity3D.UselessAttributeStripper

For iOS application, Unity3D uses IL2CPP for translating your .NET IL code to native one, which makes the size of your executable much larger than you expect. It's not easy problem to make it smaller. However, it is mandatory to keep the size under 100MB to allow iOS users to download your app over the air.

This tools will give you small margin to shrink your app a little. IL2CPP makes a small code for every attribute in your app assembly. It's small. But with thousands of .NET attributes, it may bloat your code size. This tool provide a way to remove useless attributes from your app, which doens't affect running at all. (For detailed information, read Under The Hood.)

The margin depends on your code patern. For my project which heavily exploited coroutines, it could remove 17,000 attributes from whole assemblies and reduced the uncompressed app size to 126MB from 144MB (-18MB). It seemed small but because code area in app will be encrypted before compression, this size really mattered. (For detailed information of this case, read Sample Case.)

Setup

Unzip a release zip file and run setup.py.

  • Run setup.py with administrative privilege because it may update your application directory.
  • If you didn't install Unity3D to default directory, you need to check your unity3d installation path.

For OSX

# if unity3d was installed to default directory
sudo python setup.py install    

# if unity3d was installed to /Application/Unity531
sudo python setup.py install /Application/Unity531

For Windows, run a command as administrator,

# if unity3d was installed to default directory
setup.py install    

# if unity3d was installed to C:\Program Files\Unity531
setup.py install "C:\Program Files\Unity531"

After installed, this utility will be running whenever unity3d builds application with IL2CPP.

Check what's going on

During unity3D builds application it runs a few programs like mono compiler and IL2CPP. At this time this tool will be executed and it will write log messages to file in intermediate directory. You can find log file at ./Project/Output/Data/Managed/UselessAttributeStripper.txt. (you can see sample log)

With log, you can know which attributes were removed from DLLs and the amount of removal.

- ProcessDll : /builder/GameClient/Temp/StagingArea/Data/Managed/mscorlib.dll
  - System.Runtime.InteropServices.ComVisibleAttribute : 1311
  - System.MonoTODOAttribute : 461
  - System.CLSCompliantAttribute : 374
  - (trimmed)

At the end of log, total removal infomation will be written.

* Summary *
  - System.Runtime.CompilerServices.CompilerGeneratedAttribute : 5566
  - System.Diagnostics.DebuggerHiddenAttribute : 4641
  - System.Runtime.InteropServices.ComVisibleAttribute : 1380
  - System.Runtime.CompilerServices.ExtensionAttribute : 797
  - (trimmed)

Configuration

This tool has default attribute lists to be removed. These were chosen in a conservative attitude to avoid running problem. And if you want to remove other attributes, you can specify your own attribute lists on Assets/strip-attribute.xml file. This file looks like

<strip-attribute>
  <!-- Protobuf.net (precompiler makes app don't need these attributes) -->
  <type fullname="ProtoBuf.ProtoContractAttribute"/>
  <type fullname="ProtoBuf.ProtoMemberAttribute"/>
  <!-- Project-related -->
  <type fullname="GameCommon.Data.EidCategoryAttribute"/>
  <type fullname="GameCommon.Data.RefAttribute"/>
</strip-attribute>

To let tool detecting list xml, links.xml should exist at the same directory. (Assets/links.xml for Assets/strip-attribute.xml)

unity3d.uselessattributestripper's People

Contributors

veblush avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.